Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fastson 1.2.73 NullPointerException when set AfterFilter #3443

Closed
leonchen83 opened this issue Sep 8, 2020 · 0 comments
Closed

fastson 1.2.73 NullPointerException when set AfterFilter #3443

leonchen83 opened this issue Sep 8, 2020 · 0 comments
Milestone

Comments

@leonchen83
Copy link

leonchen83 commented Sep 8, 2020

it works in 1.2.72
reproduce code

import com.alibaba.fastjson.serializer.AfterFilter;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class Main {
	public static void main(String[] args) {
		Json json = new Json();
		json.setOp(new Operator());
		try(SerializeWriter out = new SerializeWriter()) {
			JSONSerializer s = new JSONSerializer(out, new SerializeConfig());
			s.config(SerializerFeature.DisableCircularReferenceDetect, true);
			s.getAfterFilters().add(new JsonFilter());
			s.write(json);
			System.out.println(out.toString());
		}
	}
	
	static class Json {
		private Operator op;

		public Operator getOp() {
			return op;
		}

		public void setOp(Operator op) {
			this.op = op;
		}
	}
	
	static class Operator {
	}
	
	static class JsonFilter extends AfterFilter {
		
		@Override
		public void writeAfter(Object object) {
			if(object instanceof Operator) {
				writeKeyValue("operator", "operator");
			}
		}
	}
}

exception stack

Exception in thread "main" com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Json, write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Operator, fieldName : op
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:539)
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:149)
	at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312)
	at cn.nextop.thorin.admin.json.Main.main(Main.java:41)
Caused by: com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Operator, fieldName : op
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:539)
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:149)
	at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:320)
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:470)
	... 3 more
Caused by: java.lang.NullPointerException
	at com.alibaba.fastjson.serializer.AfterFilter.writeKeyValue(AfterFilter.java:26)
	at cn.nextop.thorin.admin.json.Main$JsonFilter.writeAfter(Main.java:70)
	at com.alibaba.fastjson.serializer.AfterFilter.writeAfter(AfterFilter.java:17)
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.writeAfter(JavaBeanSerializer.java:834)
	at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:502)
	... 6 more

fastjson version: 1.2.73
jdk version: openjdk-11.0.2

wenshao added a commit that referenced this issue Oct 3, 2020
…ption

fix AfterFilter NullPointer exception in #3443
@wenshao wenshao closed this as completed Oct 11, 2020
@wenshao wenshao added this to the 1.2.74 milestone Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants