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

Java objects returned from constructor functions are lost

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • None
    • core-libs
    • None
    • b82
    • generic
    • generic
    • Verified

    Description

      When "new Foo()" is used with a constructor function "Foo" that returns a java object, say object of java.util.HashMap, the return value is lost. We get empty JavaScript object instead.

      Example:

      function Func() {
         return new java.util.HashMap();
      }

      var f = new Func();
      if (! (f instanceof java.util.Map)) {
          print("FAILED: instance of java.util.Map expected")
      }


      But the above script works fine with Rhino. The issue is that whenever constructor returns non-script objects, the default empty instance that was passed as 'this' to constructor is returned. While this is okay for script types such as undefined, number, string etc., for Java objects we should return the objects returned by constructors "as is"

      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: