New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when @JsonbTransient is applied on property without setter #34

Open
ggam opened this Issue Aug 9, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@ggam
Member

ggam commented Aug 9, 2017

I'm using Yasson 1.0.

Having the following mapping:

public class Foo implements Serializable {

    @JsonbTransient
    private String bar;

    public String getBar() {
        return bar;
    }
}

AnnotationIntrospector searches for a @JsonbTransient on a setBar(String) method and since it can't find it, it marks the property as "writeable":

if (transientInfo.contains(AnnotationTarget.PROPERTY)) {
    // ...

    if(!transientInfo.contains(AnnotationTarget.SETTER)){
        builder.setWriteTransient(true);
    }
}

But later on introspectCustomization it tries to do some checks on that setter method that does not exist:

if (builder.isWriteTransient()) {
    // ...
    introspector.checkTransientIncompatible(property.getSetterElement());
}

Resulting in the following stacktrace:

Caused by: java.lang.NullPointerException
	at org.eclipse.yasson.internal.AnnotationIntrospector.checkTransientIncompatible(AnnotationIntrospector.java:534)
	at org.eclipse.yasson.internal.model.PropertyModel.introspectCustomization(PropertyModel.java:159)
	at org.eclipse.yasson.internal.model.PropertyModel.<init>(PropertyModel.java:87)
	at org.eclipse.yasson.internal.model.customization.ordering.PropertyOrdering.lambda$orderProperties$0(PropertyOrdering.java:79)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1620)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at org.eclipse.yasson.internal.model.customization.ordering.PropertyOrdering.orderProperties(PropertyOrdering.java:80)
	at org.eclipse.yasson.internal.ClassParser.parseProperties(ClassParser.java:60)
	at org.eclipse.yasson.internal.MappingContext$ParseClassModelFunction.apply(MappingContext.java:56)
	at org.eclipse.yasson.internal.MappingContext$ParseClassModelFunction.apply(MappingContext.java:37)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
	at org.eclipse.yasson.internal.MappingContext.getOrCreateClassModel(MappingContext.java:100)
	at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:57)
	at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
	at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
	at org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:79)
	at org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:35)
	at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
	at org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:118)
	at org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:76)
	at org.eclipse.yasson.internal.JsonBinding.toJson(JsonBinding.java:98)
	at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.writeTo(BaseJsonbJaxrsProvider.java:57)
	at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.writeTo$$super(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:49)
	at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:77)
	at org.jboss.weld.probe.InvocationMonitor$InterceptorAction.proceed(InvocationMonitor.java:198)
	at org.jboss.weld.probe.InvocationMonitor$InterceptorAction.proceed(InvocationMonitor.java:194)
	at org.jboss.weld.probe.InvocationMonitor$Action.perform(InvocationMonitor.java:173)
	at org.jboss.weld.probe.InvocationMonitor.monitor(InvocationMonitor.java:139)
	at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
	at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
	at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
	at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
	at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
	at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
	at xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.writeTo(Unknown Source)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:131)
	at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:60)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:120)
	at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:145)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
	at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
	at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
	at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:98)
	at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:473)
	... 62 more

Workaround for now is just annotate the getter.

@m0mus

This comment has been minimized.

Show comment
Hide comment
@m0mus

m0mus Aug 30, 2017

Member

I confirm that this issue exists. Roman, please take a look.

Member

m0mus commented Aug 30, 2017

I confirm that this issue exists. Roman, please take a look.

@m0mus m0mus added the bug label Aug 30, 2017

@m0mus m0mus added this to the 1.0.1 milestone Aug 30, 2017

m0mus added a commit that referenced this issue Aug 30, 2017

#34 - Fixed @JsonbTransient related issues
Signed-off-by: Dmitry Kornilov <dmitry.kornilov@oracle.com>

@m0mus m0mus assigned m0mus and unassigned bravehorsie Aug 30, 2017

@m0mus

This comment has been minimized.

Show comment
Hide comment
@m0mus

m0mus Aug 30, 2017

Member

Fixed.

Member

m0mus commented Aug 30, 2017

Fixed.

@m0mus m0mus closed this Aug 30, 2017

@ggam

This comment has been minimized.

Show comment
Hide comment
@ggam

ggam Aug 30, 2017

Member
Member

ggam commented Aug 30, 2017

@priyal85

This comment has been minimized.

Show comment
Hide comment
@priyal85

priyal85 Oct 5, 2017

Hi Dmitry,
I'm too facing the same issue when using Jersey which internally uses yasson for JSON bindings. In which version the fix is available. I'm still getting the issue in 1.0 which is released on June 2017.

priyal85 commented Oct 5, 2017

Hi Dmitry,
I'm too facing the same issue when using Jersey which internally uses yasson for JSON bindings. In which version the fix is available. I'm still getting the issue in 1.0 which is released on June 2017.

@m0mus

This comment has been minimized.

Show comment
Hide comment
@m0mus

m0mus Oct 6, 2017

Member
Member

m0mus commented Oct 6, 2017

@bshannon

This comment has been minimized.

Show comment
Hide comment
@bshannon

bshannon Jun 14, 2018

This bug was not completely fixed. Here's a simple test case that still fails:

import javax.json.bind.annotation.JsonbTransient;
import javax.json.bind.*;

public class Test {

    //@JsonbTransient
    //private String    binString;

    @JsonbTransient
    public String getBinString() {
        return "";
    }

    public static void main(String argv[]) throws Exception {
        Jsonb jsonb = JsonbBuilder.create();
        Test t = new Test();
        String result = jsonb.toJson(t);
        System.out.println(result);
    }
}

If you uncomment the field declaration, it works.

bshannon commented Jun 14, 2018

This bug was not completely fixed. Here's a simple test case that still fails:

import javax.json.bind.annotation.JsonbTransient;
import javax.json.bind.*;

public class Test {

    //@JsonbTransient
    //private String    binString;

    @JsonbTransient
    public String getBinString() {
        return "";
    }

    public static void main(String argv[]) throws Exception {
        Jsonb jsonb = JsonbBuilder.create();
        Test t = new Test();
        String result = jsonb.toJson(t);
        System.out.println(result);
    }
}

If you uncomment the field declaration, it works.

@bshannon bshannon reopened this Jun 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment