Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty attribute causes NullPointerException or wrong answer when comparing XML using == #5052

Closed
scabug opened this issue Oct 4, 2011 · 4 comments

Comments

@scabug
Copy link

@scabug scabug commented Oct 4, 2011

When using a "hidden" attribute, by passing in None:Option[Seq[Node]] or null:String as the value:

scala> <elem attr={None} />
res0: scala.xml.Elem = <elem ></elem>

It breaks XML equality by throwing an NPE in one direction:

scala> res0 == <elem />
java.lang.NullPointerException
	at scala.xml.NodeSeq.iterator(NodeSeq.scala:51)
	at scala.collection.IterableLike$class.foreach(IterableLike.scala:73)
	at scala.xml.NodeSeq.foreach(NodeSeq.scala:43)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
	at scala.xml.NodeSeq.map(NodeSeq.scala:43)
	at scala.xml.NodeSeq.text(NodeSeq.scala:152)
	at scala.xml.MetaData$$anonfun$asAttrMap$1.apply(MetaData.scala:168)
	at scala.xml.MetaData$$anonfun$asAttrMap$1.apply(MetaData.scala:168)
	at scala.collection.Iterator$$anon$19.next(Iterator.scala:335)
	at scala.collection.Iterator$class.foreach(Iterator.scala:660)
	at scala.collection.Iterator$$anon$19.foreach(Iterator.scala:333)
	at scala.collection.TraversableOnce$class.toMap(TraversableOnce.scala:256)
	at scala.collection.Iterator$$anon$19.toMap(Iterator.scala:333)
	at scala.xml.MetaData.asAttrMap(MetaData.scala:168)
	at scala.xml.MetaData.strict_$eq$eq(MetaData.scala:137)
	at scala.xml.Equality$class.doComparison(Equality.scala:103)
	at scala.xml.Equality$class.equals(Equality.scala:92)
	at scala.xml.MetaData.equals(MetaData.scala:74)
	at scala.xml.Node.strict_$eq$eq(Node.scala:139)
	at scala.xml.Equality$class.doComparison(Equality.scala:103)
	at scala.xml.Equality$class.equals(Equality.scala:92)
	at scala.xml.NodeSeq.equals(NodeSeq.scala:43)
	at .<init>(<console>:9)
	at .<clinit>(<console>)
	at .<init>(<console>:11)
	at .<clinit>(<console>)
	at $print(<console>)
	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 scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
	at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
	at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
	at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
	at java.lang.Thread.run(Thread.java:662)

And by returning false in the other direction:

scala> <elem /> == res0
res2: Boolean = false

Thus rendering the == function useless or inaccurate for those objects.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 4, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5052?orig=1
Reporter: Eric Winer (ewiner)
Affected Versions: 2.9.1

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 26, 2011

@jsalvata said:
The NPE is of course a bug. The false value is not: use xml_== instead -- then you'll run into the NPE bug :-D

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 26, 2011

@jsalvata said (edited on Oct 26, 2011 9:21:41 AM UTC):
I've proposed a fix: scala/scala#111

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 31, 2011

Commit Message Bot (anonymous) said:
(extempore in r25917) Fixes NPE using iterator with an XML attribute being null or None (#5052)
Also fixes incorrect size method (#5115)

Contributed by Jordi Salvat i Alabart. Closes #5052, #5115, no review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.