users@glassfish.java.net

[gf-users] Re: Logger throws NPE

From: Andreas Junius <andreas.junius_at_gmail.com>
Date: Fri, 24 Oct 2014 12:14:49 +1030

Sorry, my code snippet wasn't complete - I just wanted to keep it short.
I did the null check for bodyPart.getContentDisposition() before, so
this wasn't an issue.

Please file the bug, I've no idea where and how to do this.

Cheers,
Andy


On 24/10/14 11:46, Steven Siebert wrote:
> Andy,
>
> I have replicated what you're seeing in GF 4.1...and I agree with you
> that you should not be getting a NPE thrown in this manner and, IMO, it
> should be considered a bug...and fixing it in
> com.sun.common.util.logging.LoggingOutputStream$LoggingPrintStream.println
> would be a solid move.
>
> Although I agree with you, I came to this conclusion a little
> differently -- I do think that it's prudent to check for nulls before
> you attempt to use them. For example, I can't be sure from your
> snippit, but I believe your variable bodyPart is an insance of
> org.glassfish.jersey.media.multipart.BodyPart, give the signature of
> your method call. If true, you call bodyPart.getContentDisposition()
> itself can return null [1], causing your call to getModificationDate()
> (even in your condition check) to throw a NPE.
>
> The reason I agree with you that this is a bug, however, is the way you
> attempting to log. While you don't have a contract with
> LoggingPrintStream, the GF developers has decided to route System.out to
> an instance of this class. The developer (you) has, though, made a
> contract with PrintStream (System.out) which states " This method calls
> at first String.valueOf(x) to get the printed object's string value".
> If you further read in String.valueOf(Object), you see "if the argument
> is |null|, then a string equal to |"null"|". Thus you should NOT be
> getting a NPE.
>
> I think this smells like a legitimate bug. I can file a bug report for
> you if you would like, as I've already created a minimal reproducible
> package in testing....just let me know. If you do file, let me know the
> issue # please, and I can submit a patch for it.
>
> [1]
> https://jersey.java.net/apidocs/2.8/jersey/org/glassfish/jersey/media/multipart/BodyPart.html#getContentDisposition%28%29
>
> Regards,
>
> S
>
>
>
> On Thu, Oct 23, 2014 at 7:16 PM, Andreas Junius
> <andreas.junius_at_gmail.com <mailto:andreas.junius_at_gmail.com>> wrote:
>
> Hi GF fans,
>
> I'm developing a REST endpoint that accepts file uploads and I used
> a bunch of System.out statements to see what I can get from certain
> objects. If any method returns null, GF throws a NPE. That NPE gets
> thrown by the logging mechanism and I think that is a bug; there
> should be a null check within the logging framework, shouldn't it?
> Otherwise it'd be a bit confusing and it adds overhead, because the
> coder has to add NP checks around their test output:
>
> if (bodyPart.__getContentDisposition().__getModificationDate() !=
> null) {
>
> System.out.println(bodyPart.__getContentDisposition().__getModificationDate());
> }
>
> That's the exception:
> 2014-10-24T09:31:04.445+1030|__Severe: java.lang.NullPointerException
> at
> com.sun.common.util.logging.__LoggingOutputStream$__LoggingPrintStream.println(__LoggingOutputStream.java:230)
> at
> org.apache.felix.gogo.runtime.__threadio.ThreadPrintStream.__println(ThreadPrintStream.__java:205)
> at
> info.junius.apps.yakka.server.__FileUpload.post(FileUpload.__java:64)
> 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:483)
> at
> org.glassfish.jersey.server.__model.internal.__ResourceMethodInvocationHandle__rFactory$1.invoke(__ResourceMethodInvocationHandle__rFactory.java:81)
> at
> org.glassfish.jersey.server.__model.internal.__AbstractJavaResourceMethodDisp__atcher.invoke(__AbstractJavaResourceMethodDisp__atcher.java:125)
> at
> org.glassfish.jersey.server.__model.internal.__JavaResourceMethodDispatcherPr__ovider$TypeOutInvoker.__doDispatch(__JavaResourceMethodDispatcherPr__ovider.java:195)
> at
> org.glassfish.jersey.server.__model.internal.__AbstractJavaResourceMethodDisp__atcher.dispatch(__AbstractJavaResourceMethodDisp__atcher.java:91)
> at
> org.glassfish.jersey.server.__model.ResourceMethodInvoker.__invoke(ResourceMethodInvoker.__java:346)
> at
> org.glassfish.jersey.server.__model.ResourceMethodInvoker.__apply(ResourceMethodInvoker.__java:341)
> at
> org.glassfish.jersey.server.__model.ResourceMethodInvoker.__apply(ResourceMethodInvoker.__java:101)
> at
> org.glassfish.jersey.server.__ServerRuntime$1.run(__ServerRuntime.java:224)
> at
> org.glassfish.jersey.internal.__Errors$1.call(Errors.java:271)
> at
> org.glassfish.jersey.internal.__Errors$1.call(Errors.java:267)
> at
> org.glassfish.jersey.internal.__Errors.process(Errors.java:__315)
> at
> org.glassfish.jersey.internal.__Errors.process(Errors.java:__297)
> at
> org.glassfish.jersey.internal.__Errors.process(Errors.java:__267)
> at
> org.glassfish.jersey.process.__internal.RequestScope.__runInScope(RequestScope.java:__317)
> at
> org.glassfish.jersey.server.__ServerRuntime.process(__ServerRuntime.java:198)
> at
> org.glassfish.jersey.server.__ApplicationHandler.handle(__ApplicationHandler.java:946)
> at
> org.glassfish.jersey.servlet.__WebComponent.service(__WebComponent.java:323)
> at
> org.glassfish.jersey.servlet.__ServletContainer.service(__ServletContainer.java:372)
> at
> org.glassfish.jersey.servlet.__ServletContainer.service(__ServletContainer.java:335)
> at
> org.glassfish.jersey.servlet.__ServletContainer.service(__ServletContainer.java:218)
> at
> org.apache.catalina.core.__StandardWrapper.service(__StandardWrapper.java:1682)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__internalDoFilter(__ApplicationFilterChain.java:__344)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__doFilter(__ApplicationFilterChain.java:__214)
> at
> info.junius.apps.yakka.server.__CryptographyFilter.doFilter(__CryptographyFilter.java:135)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__internalDoFilter(__ApplicationFilterChain.java:__256)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__doFilter(__ApplicationFilterChain.java:__214)
> at
> info.junius.apps.yakka.server.__HeaderFilter.doFilter(__HeaderFilter.java:50)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__internalDoFilter(__ApplicationFilterChain.java:__256)
> at
> org.apache.catalina.core.__ApplicationFilterChain.__doFilter(__ApplicationFilterChain.java:__214)
> at
> org.apache.catalina.core.__StandardWrapperValve.invoke(__StandardWrapperValve.java:316)
> at
> org.apache.catalina.core.__StandardContextValve.invoke(__StandardContextValve.java:160)
> at
> org.apache.catalina.core.__StandardPipeline.doInvoke(__StandardPipeline.java:734)
> at
> org.apache.catalina.core.__StandardPipeline.invoke(__StandardPipeline.java:673)
> at
> com.sun.enterprise.web.__WebPipeline.invoke(__WebPipeline.java:99)
> at
> org.apache.catalina.core.__StandardHostValve.invoke(__StandardHostValve.java:174)
> at
> org.apache.catalina.connector.__CoyoteAdapter.doService(__CoyoteAdapter.java:357)
> at
> org.apache.catalina.connector.__CoyoteAdapter.service(__CoyoteAdapter.java:260)
> at
> com.sun.enterprise.v3.__services.impl.ContainerMapper.__service(ContainerMapper.java:__188)
> at
> org.glassfish.grizzly.http.__server.HttpHandler.runService(__HttpHandler.java:191)
> at
> org.glassfish.grizzly.http.__server.HttpHandler.doHandle(__HttpHandler.java:168)
> at
> org.glassfish.grizzly.http.__server.HttpServerFilter.__handleRead(HttpServerFilter.__java:189)
> at
> org.glassfish.grizzly.__filterchain.ExecutorResolver$__9.execute(ExecutorResolver.__java:119)
> at
> org.glassfish.grizzly.__filterchain.__DefaultFilterChain.__executeFilter(__DefaultFilterChain.java:288)
> at
> org.glassfish.grizzly.__filterchain.__DefaultFilterChain.__executeChainPart(__DefaultFilterChain.java:206)
> at
> org.glassfish.grizzly.__filterchain.__DefaultFilterChain.execute(__DefaultFilterChain.java:136)
> at
> org.glassfish.grizzly.__filterchain.__DefaultFilterChain.process(__DefaultFilterChain.java:114)
> at
> org.glassfish.grizzly.__ProcessorExecutor.execute(__ProcessorExecutor.java:77)
> at
> org.glassfish.grizzly.nio.__transport.TCPNIOTransport.__fireIOEvent(TCPNIOTransport.__java:838)
> at
> org.glassfish.grizzly.__strategies.AbstractIOStrategy.__fireIOEvent(__AbstractIOStrategy.java:113)
> at
> org.glassfish.grizzly.__strategies.__WorkerThreadIOStrategy.run0(__WorkerThreadIOStrategy.java:__115)
> at
> org.glassfish.grizzly.__strategies.__WorkerThreadIOStrategy.access$__100(WorkerThreadIOStrategy.__java:55)
> at
> org.glassfish.grizzly.__strategies.__WorkerThreadIOStrategy$__WorkerThreadRunnable.run(__WorkerThreadIOStrategy.java:__135)
> at
> org.glassfish.grizzly.__threadpool.AbstractThreadPool$__Worker.doWork(__AbstractThreadPool.java:564)
> at
> org.glassfish.grizzly.__threadpool.AbstractThreadPool$__Worker.run(AbstractThreadPool.__java:544)
> at java.lang.Thread.run(Thread.__java:745)
>
>
>
> Cheers,
> Andy