NPE when accidentally saving non-public classes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NPE when accidentally saving non-public classes

Eric Crahen-3

I noticed that if I add a member to something persisted through XStream that itself is non-public, I'll get an NPE. For example,
in the exception below my PMDPublisherDescriptor contained a reference to an instance of a class that was package private.
I'm not sure if you have the power to do this within XmlFile, but if it were possible to issue a error/warning that says something
like I can't persist the field named "XXX" because of whatever the reason is - or just skip
non-public fields in the same way you would transient that might be better. Either the developer would get a message
explaining the problem - or they would just not have an error at all. I haven't looked at XmlFile that much so I don't know how much
is Hudson and how much is just inherited from XStream.

 

Example:

java.lang.NullPointerException
at hudson.util.XStream2$AssociatedConverterImpl.findConverter(XStream2.java:54)
at hudson.util.XStream2$AssociatedConverterImpl.canConvert (XStream2.java:70)
at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:44)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(ReferenceByXPathMarshaller.java :23)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.writeField(ReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.visit(ReflectionConverter.java :59)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:108)
at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.marshal (ReflectionConverter.java:44)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(ReferenceByXPathMarshaller.java:36)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java :46)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java:17)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:476)
at com.thoughtworks.xstream.XStream.marshal (XStream.java:466)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:449)
at hudson.XmlFile.write(XmlFile.java:126)
at hudson.model.Descriptor.save(Descriptor.java:152)
at hudson.plugins.pmd.PMDPublisherDescriptor.configure (PMDPublisherDescriptor.java:53)
at hudson.model.Hudson.doConfigSubmit(Hudson.java:900)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java :50)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:59)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:224)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:169)
at org.kohsuke.stapler.Stapler.service(Stapler.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.mortbay.jetty.servlet.ServletHolder.handle (ServletHolder.java:491)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
at org.mortbay.jetty.servlet.SessionHandler.handle (SessionHandler.java:231)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:683)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:390)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle (ContextHandlerCollection.java:146)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
at org.mortbay.jetty.Server.handle (Server.java:281)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:765)
at org.mortbay.jetty.HttpParser.parseNext (HttpParser.java:627)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java :329)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java :619)


--

- Eric
Reply | Threaded
Open this post in threaded view
|

Re: NPE when accidentally saving non-public classes

Kohsuke Kawaguchi-2
This is reported against 1.79 and already fixed in the current trunk.

Will be posting 1.80 shortly.

Eric Crahen wrote:

> I noticed that if I add a member to something persisted through
> XStream that itself is non-public, I'll get an NPE. For example,
> in the exception below my PMDPublisherDescriptor contained a reference
> to an instance of a class that was package private.
> I'm not sure if you have the power to do this within XmlFile, but if
> it were possible to issue a error/warning that says something
> like I can't persist the field named "XXX" because of whatever the
> reason is - or just skip
> non-public fields in the same way you would transient that might be
> better. Either the developer would get a message
> explaining the problem - or they would just not have an error at all.
> I haven't looked at XmlFile that much so I don't know how much
> is Hudson and how much is just inherited from XStream.
>
>
>
> Example:
>
> java.lang.NullPointerException
> at hudson.util.XStream2$AssociatedConverterImpl.findConverter(XStream2.java:54)
> at hudson.util.XStream2$AssociatedConverterImpl.canConvert(XStream2.java:70)
> at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:44)
> at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(ReferenceByXPathMarshaller.java:23)
> at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.writeField(ReflectionConverter.java:81)
> at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.visit(ReflectionConverter.java:59)
> at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:108)
> at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.marshal(ReflectionConverter.java:44)
> at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(ReferenceByXPathMarshaller.java:36)
> at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:46)
> at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java:17)
> at com.thoughtworks.xstream.XStream.marshal(XStream.java:476)
> at com.thoughtworks.xstream.XStream.marshal(XStream.java:466)
> at com.thoughtworks.xstream.XStream.toXML(XStream.java:449)
> at hudson.XmlFile.write(XmlFile.java:126)
> at hudson.model.Descriptor.save(Descriptor.java:152)
> at hudson.plugins.pmd.PMDPublisherDescriptor.configure(PMDPublisherDescriptor.java:53)
> at hudson.model.Hudson.doConfigSubmit(Hudson.java:900)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:50)
> at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:59)
> at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
> at org.kohsuke.stapler.Stapler.invoke(Stapler.java:224)
> at org.kohsuke.stapler.Stapler.invoke(Stapler.java:169)
> at org.kohsuke.stapler.Stapler.service(Stapler.java:68)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
> at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
> at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
> at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:231)
> at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:683)
> at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:390)
> at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:146)
> at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
> at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
> at org.mortbay.jetty.Server.handle(Server.java:281)
> at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
> at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:765)
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:627)
> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
> at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
>
>
>

--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NPE when accidentally saving non-public classes

Eric Crahen-3
I'll start checking the issues more closely. You must be gaining more users, ;)

On 2/10/07, Kohsuke Kawaguchi <[hidden email]> wrote:
This is reported against 1.79 and already fixed in the current trunk.

Will be posting 1.80 shortly.

Eric Crahen wrote:

> I noticed that if I add a member to something persisted through
> XStream that itself is non-public, I'll get an NPE. For example,
> in the exception below my PMDPublisherDescriptor contained a reference
> to an instance of a class that was package private.
> I'm not sure if you have the power to do this within XmlFile, but if
> it were possible to issue a error/warning that says something
> like I can't persist the field named "XXX" because of whatever the
> reason is - or just skip
> non-public fields in the same way you would transient that might be
> better. Either the developer would get a message
> explaining the problem - or they would just not have an error at all.
> I haven't looked at XmlFile that much so I don't know how much
> is Hudson and how much is just inherited from XStream.
>
>
>
> Example:
>
> java.lang.NullPointerException
>       at hudson.util.XStream2$AssociatedConverterImpl.findConverter(XStream2.java:54)
>       at hudson.util.XStream2$AssociatedConverterImpl.canConvert(XStream2.java:70)
>       at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType (DefaultConverterLookup.java:44)
>       at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(ReferenceByXPathMarshaller.java:23)
>       at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.writeField (ReflectionConverter.java:81)
>       at com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.visit(ReflectionConverter.java:59)
>       at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields (PureJavaReflectionProvider.java:108)
>       at com.thoughtworks.xstream.converters.reflection.ReflectionConverter.marshal(ReflectionConverter.java:44)
>       at com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother (ReferenceByXPathMarshaller.java:36)
>       at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:46)
>       at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java :17)
>       at com.thoughtworks.xstream.XStream.marshal(XStream.java:476)
>       at com.thoughtworks.xstream.XStream.marshal(XStream.java:466)
>       at com.thoughtworks.xstream.XStream.toXML(XStream.java :449)
>       at hudson.XmlFile.write(XmlFile.java:126)
>       at hudson.model.Descriptor.save(Descriptor.java:152)
>       at hudson.plugins.pmd.PMDPublisherDescriptor.configure(PMDPublisherDescriptor.java :53)
>       at hudson.model.Hudson.doConfigSubmit(Hudson.java:900)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39)
>       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at org.kohsuke.stapler.Function$InstanceFunction.invoke (Function.java:50)
>       at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:59)
>       at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
>       at org.kohsuke.stapler.Stapler.invoke (Stapler.java:224)
>       at org.kohsuke.stapler.Stapler.invoke(Stapler.java:169)
>       at org.kohsuke.stapler.Stapler.service(Stapler.java:68)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java :802)
>       at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
>       at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
>       at org.mortbay.jetty.security.SecurityHandler.handle (SecurityHandler.java:185)
>       at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:231)
>       at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:683)
>       at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:390)
>       at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:146)
>       at org.mortbay.jetty.handler.HandlerCollection.handle (HandlerCollection.java:123)
>       at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
>       at org.mortbay.jetty.Server.handle(Server.java:281)
>       at org.mortbay.jetty.HttpConnection.handleRequest (HttpConnection.java:457)
>       at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:765)
>       at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:627)
>       at org.mortbay.jetty.HttpParser.parseAvailable (HttpParser.java:209)
>       at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
>       at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
>       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask (ThreadPoolExecutor.java:885)
>       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>       at java.lang.Thread.run(Thread.java:619)
>
>
>


--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]




--

- Eric
Reply | Threaded
Open this post in threaded view
|

Re: NPE when accidentally saving non-public classes

Kohsuke Kawaguchi-2
Eric Crahen wrote:
> I'll start checking the issues more closely.

No worries.

 > You must be gaining more users,
> ;)

If so, that's great.

>
> On 2/10/07, Kohsuke Kawaguchi <[hidden email]> wrote:
>>
>> This is reported against 1.79 and already fixed in the current trunk.
>>
>> Will be posting 1.80 shortly.
>>
>> Eric Crahen wrote:
>> > I noticed that if I add a member to something persisted through
>> > XStream that itself is non-public, I'll get an NPE. For example,
>> > in the exception below my PMDPublisherDescriptor contained a reference
>> > to an instance of a class that was package private.
>> > I'm not sure if you have the power to do this within XmlFile, but if
>> > it were possible to issue a error/warning that says something
>> > like I can't persist the field named "XXX" because of whatever the
>> > reason is - or just skip
>> > non-public fields in the same way you would transient that might be
>> > better. Either the developer would get a message
>> > explaining the problem - or they would just not have an error at all.
>> > I haven't looked at XmlFile that much so I don't know how much
>> > is Hudson and how much is just inherited from XStream.
>> >
>> >
>> >
>> > Example:
>> >
>> > java.lang.NullPointerException
>> >       at hudson.util.XStream2$AssociatedConverterImpl.findConverter(
>> XStream2.java:54)
>> >       at hudson.util.XStream2$AssociatedConverterImpl.canConvert(
>> XStream2.java:70)
>> >       at
>> com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType
>> (DefaultConverterLookup.java:44)
>> >       at
>> com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(
>> ReferenceByXPathMarshaller.java:23)
>> >       at
>> com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.writeField
>> (ReflectionConverter.java:81)
>> >       at
>> com.thoughtworks.xstream.converters.reflection.ReflectionConverter$1.visit
>> (ReflectionConverter.java:59)
>> >       at
>> com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields
>> (PureJavaReflectionProvider.java:108)
>> >       at
>> com.thoughtworks.xstream.converters.reflection.ReflectionConverter.marshal
>> (ReflectionConverter.java:44)
>> >       at
>> com.thoughtworks.xstream.core.ReferenceByXPathMarshaller.convertAnother(
>> ReferenceByXPathMarshaller.java:36)
>> >       at com.thoughtworks.xstream.core.TreeMarshaller.start(
>> TreeMarshaller.java:46)
>> >       at
>> com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(
>> ReferenceByXPathMarshallingStrategy.java:17)
>> >       at com.thoughtworks.xstream.XStream.marshal(XStream.java:476)
>> >       at com.thoughtworks.xstream.XStream.marshal(XStream.java:466)
>> >       at com.thoughtworks.xstream.XStream.toXML(XStream.java:449)
>> >       at hudson.XmlFile.write(XmlFile.java:126)
>> >       at hudson.model.Descriptor.save(Descriptor.java:152)
>> >       at hudson.plugins.pmd.PMDPublisherDescriptor.configure(
>> PMDPublisherDescriptor.java:53)
>> >       at hudson.model.Hudson.doConfigSubmit(Hudson.java:900)
>> >       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >       at sun.reflect.NativeMethodAccessorImpl.invoke(
>> NativeMethodAccessorImpl.java:39)
>> >       at sun.reflect.DelegatingMethodAccessorImpl.invoke(
>> DelegatingMethodAccessorImpl.java:25)
>> >       at java.lang.reflect.Method.invoke(Method.java:597)
>> >       at org.kohsuke.stapler.Function$InstanceFunction.invoke(
>> Function.java:50)
>> >       at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:59)
>> >       at org.kohsuke.stapler.NameBasedDispatcher.dispatch(
>> NameBasedDispatcher.java:30)
>> >       at org.kohsuke.stapler.Stapler.invoke(Stapler.java:224)
>> >       at org.kohsuke.stapler.Stapler.invoke(Stapler.java:169)
>> >       at org.kohsuke.stapler.Stapler.service(Stapler.java:68)
>> >       at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>> >       at org.mortbay.jetty.servlet.ServletHolder.handle(
>> ServletHolder.java:491)
>> >       at org.mortbay.jetty.servlet.ServletHandler.handle(
>> ServletHandler.java:367)
>> >       at org.mortbay.jetty.security.SecurityHandler.handle(
>> SecurityHandler.java:185)
>> >       at org.mortbay.jetty.servlet.SessionHandler.handle(
>> SessionHandler.java:231)
>> >       at org.mortbay.jetty.handler.ContextHandler.handle(
>> ContextHandler.java:683)
>> >       at org.mortbay.jetty.webapp.WebAppContext.handle(
>> WebAppContext.java:390)
>> >       at org.mortbay.jetty.handler.ContextHandlerCollection.handle(
>> ContextHandlerCollection.java:146)
>> >       at org.mortbay.jetty.handler.HandlerCollection.handle(
>> HandlerCollection.java:123)
>> >       at org.mortbay.jetty.handler.HandlerWrapper.handle(
>> HandlerWrapper.java:141)
>> >       at org.mortbay.jetty.Server.handle(Server.java:281)
>> >       at org.mortbay.jetty.HttpConnection.handleRequest(
>> HttpConnection.java:457)
>> >       at org.mortbay.jetty.HttpConnection$RequestHandler.content(
>> HttpConnection.java:765)
>> >       at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:627)
>> >       at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java
>> :209)
>> >       at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java
>> :357)
>> >       at org.mortbay.io.nio.SelectChannelEndPoint.run(
>> SelectChannelEndPoint.java:329)
>> >       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
>> ThreadPoolExecutor.java:885)
>> >       at java.util.concurrent.ThreadPoolExecutor$Worker.run(
>> ThreadPoolExecutor.java:907)
>> >       at java.lang.Thread.run(Thread.java:619)
>> >
>> >
>> >
>>
>>
>> --
>> Kohsuke Kawaguchi
>> Sun Microsystems                   [hidden email]
>>
>>
>
>

--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]

smime.p7s (4K) Download Attachment