Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128485

DOM methods (e.g. Node#insertBefore) fail on null parameters


    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.0
    • Component/s: javafx
    • Subcomponent:


      Some DOM methods have useful and defined non-error behavior when a parameter is null.
      For example org.w3c.dom.Node#insertBefore(Node newChild, Node refChild) is specified
      "If refChild is null, insert newChild at the end of the list of children."
      Our implementation results in a NullPointerException.

      The reason is simple: CodeGeneratorJava.pm generates the NodeImpl.java which contains methods that are just wrappers for the native methods that work on native "peer" references. The refChild is parameter is converted using this expression:
        ((NodeImpl) refChild).getPeer())
      which of course fails is refChild is null. What we want is:
        (refChild==null?0:((NodeImpl) refChild).getPeer())
      The problem is we can't just fix the generated code - we have to fix the generator.

      The easy fix is to change paramForNativeJavaCall in CodeGeneratorJava.pm:
          # Otherwise it's a DOM type, so should pass a native peer.
          return "($paramName==null?0:((${paramType}Impl) $paramName).getPeer())";
      However, note that some (most?) DOM parametersare not allowed to be null. For example if newNode (instead of refNode) is null, and we make the above change to CodeGeneratorJava.pm we will get a DOMException (from the native layer) rather than a NullPointerException.
      NullPointerException seems more natural. Furthermore, I've looked at the JAXP source code, and it appears it throws a NullPointerException if newNode==null.

      So I think we need a more complex fix that only only converts Java null to native 0 (i.e. native NULL) for specific parameters. I'm testing such a fix.




            • Assignee:
              pbothner Per Bothner (Inactive)
              pbothner Per Bothner (Inactive)
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: