Re: NullPointerException in Element.setAttribute(final String name, final String value, final Namespace ns)
<[email protected]> Sat, 7 Apr 2012 00:53:40 +0300
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <6A01160BED1CB74CB2F447CB21ED5C110119B039EC12@INT03EXVS3.mcint.local> |
the stack trace belongs to JDOM 1.1.3 -----Original Message----- From: Saavedra Gisella Sent: Friday, April 06, 2012 2:49 PM To: 'Rolf Lear' Cc: [email protected] Subject: RE: [jdom-interest] NullPointerException in Element.setAttribute(final String name, final String value, final Namespace ns) Rolf, I believe you might be looking at the wrong method: This is JDOM 1.0 (ns is passed as null) public Element setAttribute(String name, String value, Namespace ns) { return setAttribute(new Attribute(name, value, ns)); } Inside this code, the constructor new Attribute(name, value, ns) calls: public Attribute(String name, String value, Namespace namespace) { setName(name); setValue(value); setNamespace(namespace); } Here setNamespace(namespace) calls: public Attribute setNamespace(Namespace namespace) { if (namespace == null) { namespace = Namespace.NO_NAMESPACE; } // Verify the attribute isn't trying to be in a default namespace // Attributes can't be in a default namespace if (namespace != Namespace.NO_NAMESPACE && namespace.getPrefix().equals("")) { throw new IllegalNameException("", "attribute namespace", "An attribute namespace without a prefix can only be the " + "NO_NAMESPACE namespace"); } this.namespace = namespace; return this; } where namespace being null is set to NO_NAMESPACE. Stack trace (JODM 1.1.3): java.lang.NullPointerException at org.jdom.AttributeList.indexOf(AttributeList.java:378) at org.jdom.AttributeList.get(AttributeList.java:366) at org.jdom.Element.getAttribute(Element.java:1004) at org.jdom.Element.setAttribute(Element.java:1178) at com.navis.argo.business.snx.AbstractXmlExporter.setAttribute(AbstractXmlExporter.java:40) -------------- -----Original Message----- From: Rolf Lear [mailto:[email protected]] Sent: Friday, April 06, 2012 2:40 PM To: Saavedra Gisella Cc: [email protected] Subject: Re: [jdom-interest] NullPointerException in Element.setAttribute(final String name, final String value, final Namespace ns) Hi Gisella. I have looked through the JDOM 1.0 code. JDOM 1.0 was released in September 2004. Here's the code as it was at the time: Here's the getAttribute method: https://github.com/hunterhacker/jdom/blob/jdom-1.0/core/src/java/org/jdom/Element.java#L980 Here's the attributes.get(String,Namespace) method: https://github.com/hunterhacker/jdom/blob/jdom-1.0/core/src/java/org/jdom/AttributeList.java#L365 And that calls the indexOf(String,Namespace) method: https://github.com/hunterhacker/jdom/blob/jdom-1.0/core/src/java/org/jdom/AttributeList.java#L377 Which calls namespace.getURI(). The way I see it is that JDOM 1.0 would always throw a NullPointerException if you gave it a null Namespace. I don't think it would have ever worked in JDOM 1.0... Did you have your own custom build of JDOM 1.0? Rolf On 06/04/2012 5:08 PM, Rolf Lear wrote: > Hi Gisella. > > Is it possible to send us a stack trace, at least the parts including > the org.jdom.* code. > > Thanks > > Rolf > > > On 06/04/2012 1:43 PM, [email protected] wrote: >> I just upgraded from jdom 1.0 to jdom 1.1.3 >> >> and I was setting an attribute where the namespace was NULL. >> >> The old code was different, it was NOT calling get(...), so it was setting >> the namespace to namespace.NO_NAMESPACE when the namespace was NULL, >> >> before calling this get(...) >> >> but the new code, when it calls getAttribute(name, ns) (first line of >> method described) >> >> is getting a null pointer on the namespace. >> >> Probably the namespace needs to be set to NO_NAMESPACE before calling >> get(..) when it is NULL. >> >> *Gisella Saavedra** >> *Framework Team >> [email protected] <mailto:[email protected]>_ >> >> >> >> http://www.navis.com/images/spacer.gif >> >> 1000 Broadway, Suite 150, Oakland, CA 94607 | T+1 510 267 5123 T Main+1 >> 510 267 5000 F+1 510 267 5100 | _http://www.navis.com >> <http://www.navis.com/>_ >> >> >> >> _______________________________________________ >> To control your jdom-interest membership: >> http://www.jdom.org/mailman/options/jdom-interest/[email protected] > > _______________________________________________ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/[email protected] > _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected]