You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by Todd Wells <to...@theplatform.com> on 2008/04/28 23:30:04 UTC
NullPointerException when calling ClientResponse.getDocument()
I¹d like for the dev team to review this issue, which has turned into a
blocker for me. I¹ve been digging into the Abdera code a bit and I suspect
this could actually be a race condition where the parser isn¹t initialized
by the time I call ClientResponse.getDocument(). I think the
NullPointerException is due to the overloaded method of getDocument()
calling parser.getOptions() when parser is null before whatever is
responsible for initializing the parser has succeeded. The exact same call
succeeds when I run this inside of IDEA, which I suspect may be slowing
things down just enough so that I don¹t hit the race condition. Either that
or there¹s some strange class loader issue going on here. Because the NPE
doesn¹t occur when I¹m running in IDEA or in IDEA¹s debugger, I can¹t step
into the Abdera code and debug it. I¹m on a gigabit LAN so my HTTP response
is getting returned very quickly, if that could in any way be contributing
to the issue.
Either way, I could really use some advice on this or I may need to abandon
Abdera altogether and roll my own client. In this example I was actually
calling getDocument() from groovy code, but I tried encapsulating that code
in a java class, which didn¹t seem to make any difference.
The code which is generating this exception is very straightforward (this is
groovy, but I assume you can translate). The exception occurs at the
getDocument() call.
List<Entry> getHistoryEntriesForArtifact(String artifactName) {
artifactName = sanitizePath(artifactName)
def feedUri =
"${uri.toString()}/api/registry/${workspace}/${artifactName};history"
def abdera = new Abdera()
def client = new AbderaClient(abdera)
if (proxy) {
client.setProxy proxy.host, proxy.port.toInteger()
}
def reqOptions = client.getDefaultRequestOptions()
reqOptions.setUseLocalCache(false)
reqOptions.setAuthorization(getBasicAuthHeaderForCredentials(username,
password))
ClientResponse response = client.get(feedUri, reqOptions)
if (response.getStatus() == 404) {
throw new ArtifactNotFoundException("Couldn't find
${artifactName}")
}
Document<Feed> feedDoc = response.getDocument()
return feedDoc.getRoot().getEntries()
}
------ Forwarded Message
From: Todd Wells <to...@theplatform.com>
Reply-To: <ab...@incubator.apache.org>
Date: Fri, 25 Apr 2008 15:38:01 -0700
To: <ab...@incubator.apache.org>
Subject: NullPointerException when calling ClientResponse.getDocument()
I¹m stumped. I have this repeatable case where ClientResponse.getDocument()
results in a NullPointerException, even though a fully-formed atom document
was successfully retrieved.
Here¹s the weird part and sorry there are so many caveats here this is
running from inside an ant task that I¹ve written. When I run it inside of
the debugger or IDE (while not debugging) it works just fine. When I run it
via the command line I get the NPE every time. I¹m routing both attempts
through an HTTP proxy (fiddler) and I can see that the HTTP request and
response are the same in both cases , but in the one case Abdera throws the
NPE. I¹ve been poking at this for several hours now and I¹m at my wit¹s
end. Here¹s the stack trace I¹m getting. Any idea how I could further nail
this down?
Caused by: java.lang.NullPointerException
at
org.apache.abdera.protocol.client.AbstractClientResponse.getDocument(Abstrac
tClientResponse.java:96)
at
org.apache.abdera.protocol.client.AbstractClientResponse.getDocument(Abstrac
tClientResponse.java:74)
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:585)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:754)
at
org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.jav
a:765)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:75
3)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptByteco
deAdapter.java:167)
My best (and somewhat feeble) guess is that there¹s something different in
the class paths that is causing the difference in behavior. What that might
be, I have no idea.
------ End of Forwarded Message