users@glassfish.java.net

[gf-users] Re: Logger throws NPE

From: Steven Siebert <smsiebe_at_gmail.com>
Date: Fri, 24 Oct 2014 06:01:04 -0400

No problem, issue is here: https://java.net/jira/browse/GLASSFISH-21242



On Thu, Oct 23, 2014 at 9:44 PM, Andreas Junius <andreas.junius_at_gmail.com>
wrote:

> 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
>>
>