You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For DefaultJacksonJaxbJsonProvider, the no params constructor has been removed in PR. And it's in branch 2.x, 3.0, 3.1, 4.0
Then with a manual merge operation, the no params constructor has been bring back to 3.0, 3.1, 4.0. but still not in 2.x
There is a field named commonConfig in the DefaultJacksonJaxbJsonProvider, and if the field is not inject, there will be a NPE when invoking filterModules method. For most case it can work fine, since the commonConfig can be auto injected through the constructor with two params annotated with @Context. But if the instance is created by the constructor, it will fail at first time, then always says "The resource configuration is not modifiable in this context" which make person confused.
A typical use case is that we extend the DefaultJacksonJaxbJsonProvider and override the readFrom method to add some log. As the default constructor don't have any params, the commonConfig is null and will meet the Exception in 3.0, 3.1, 4.0.
But for 2.x, it will fail during compile "no suitable constructor found for DefaultJacksonJaxbJsonProvider(no arguments)".
From the commit, it more seems like not intend to add this constructor back in 3.0, 3.1, 4.0.
So I create a sample PR to keep the same behavior with 2.x #5735
Reproduce:
Extend DefaultJacksonJaxbJsonProvider and register the provider
Exception for the first call
java.lang.NullPointerException: Cannot invoke "jakarta.ws.rs.core.Configuration.getProperties()" because "this.commonConfig" is null
at org.glassfish.jersey.jackson.internal.DefaultJacksonJaxbJsonProvider.filterModules(DefaultJacksonJaxbJsonProvider.java:77)
at org.glassfish.jersey.jackson.internal.DefaultJacksonJaxbJsonProvider.findAndRegisterModules(DefaultJacksonJaxbJsonProvider.java:67)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1268)
at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:362)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:410)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:466)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:59)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:47)
at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:74)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:131)
at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:176)
at org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:98)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2109)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:93)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:67)
at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.lambda$getAllServiceHolders$0(AbstractHk2InjectionManager.java:136)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getAllServiceHolders(AbstractHk2InjectionManager.java:140)
at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getAllServiceHolders(ImmediateHk2InjectionManager.java:30)
at org.glassfish.jersey.internal.inject.Providers.getServiceHolders(Providers.java:307)
at org.glassfish.jersey.internal.inject.Providers.getCustomProviders(Providers.java:151)
at org.glassfish.jersey.message.internal.MessageBodyFactory.initialize(MessageBodyFactory.java:219)
at org.glassfish.jersey.message.internal.MessageBodyFactory$MessageBodyWorkersConfigurator.postInit(MessageBodyFactory.java:114)
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$2(ApplicationHandler.java:366)
at java.base/java.util.Arrays$ArrayList.forEach(Arrays.java:4204)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:366)
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:310)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:309)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:274)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:338)
at jakarta.servlet.GenericServlet.init(GenericServlet.java:178)
at jakarta.servlet.http.HttpServlet.init(HttpServlet.java:107)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:944)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:662)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:115)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:833)
Exception for the following call
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:252)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:199)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:432)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:306)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:338)
at jakarta.servlet.GenericServlet.init(GenericServlet.java:178)
at jakarta.servlet.http.HttpServlet.init(HttpServlet.java:107)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:944)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:662)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:115)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:833)
The text was updated successfully, but these errors were encountered:
Yougoss
changed the title
NPE when using DefaultJacksonJaxbJsonProvider constructor without params to create instance
NPE when using DefaultJacksonJaxbJsonProvider no params constructor to create instance
Aug 29, 2024
For DefaultJacksonJaxbJsonProvider, the no params constructor has been removed in PR. And it's in branch 2.x, 3.0, 3.1, 4.0
Then with a manual merge operation, the no params constructor has been bring back to 3.0, 3.1, 4.0. but still not in 2.x
There is a field named commonConfig in the DefaultJacksonJaxbJsonProvider, and if the field is not inject, there will be a NPE when invoking filterModules method. For most case it can work fine, since the commonConfig can be auto injected through the constructor with two params annotated with
@Context
. But if the instance is created by the constructor, it will fail at first time, then always says "The resource configuration is not modifiable in this context" which make person confused.A typical use case is that we extend the DefaultJacksonJaxbJsonProvider and override the readFrom method to add some log. As the default constructor don't have any params, the commonConfig is null and will meet the Exception in 3.0, 3.1, 4.0.
But for 2.x, it will fail during compile "no suitable constructor found for DefaultJacksonJaxbJsonProvider(no arguments)".
From the commit, it more seems like not intend to add this constructor back in 3.0, 3.1, 4.0.
So I create a sample PR to keep the same behavior with 2.x
#5735
Reproduce:
Extend DefaultJacksonJaxbJsonProvider and register the provider
Exception for the first call
Exception for the following call
The text was updated successfully, but these errors were encountered: