Scala Programming Language
  1. Scala Programming Language
  2. SI-5052

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.1
    • Fix Version/s: None
    • Component/s: XML Support
    • Labels:

      Description

      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.

        Activity

        Hide
        Jordi Salvat i Alabart added a comment -

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

        Show
        Jordi Salvat i Alabart added a comment - The NPE is of course a bug. The false value is not: use xml_== instead – then you'll run into the NPE bug :-D
        Hide
        Jordi Salvat i Alabart added a comment - - edited
        Show
        Jordi Salvat i Alabart added a comment - - edited I've proposed a fix: https://github.com/scala/scala/pull/111
        Hide
        Commit Message Bot added a comment -

        (extempore in r25917) Fixes NPE using iterator with an XML attribute being null or None (SI-5052)
        Also fixes incorrect size method (SI-5115)

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

        Show
        Commit Message Bot added a comment - (extempore in r25917 ) Fixes NPE using iterator with an XML attribute being null or None ( SI-5052 ) Also fixes incorrect size method ( SI-5115 ) Contributed by Jordi Salvat i Alabart. Closes SI-5052 , SI-5115 , no review.

          People

          • Assignee:
            Unassigned
            Reporter:
            Eric Winer
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development