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

ClassCastException when converting return value of a Java method to boolean

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 8
    • 8
    • core-libs
    • None
    • b117
    • generic
    • generic

    Backports

      Description

        Script:

        var x = new java.util.HashMap()
        x.put('test', new java.io.File('test'))
        if (x.get('test')) {
            print('Found!')
        }

        Exception:


         
        Exception in thread "main" java.lang.ClassCastException: java.io.File cannot be cast to java.lang.Number
        at sun.invoke.util.ValueConversions.primitiveConversion(ValueConversions.java:199)
        at sun.invoke.util.ValueConversions.unboxBoolean(ValueConversions.java:95)
        at jdk.nashorn.internal.scripts.Script$t.runScript(t.js:5)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:498)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:207)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
        at jdk.nashorn.tools.Shell.apply(Shell.java:381)
        at jdk.nashorn.tools.Shell.runScripts(Shell.java:310)
        at jdk.nashorn.tools.Shell.run(Shell.java:166)
        at jdk.nashorn.tools.Shell.main(Shell.java:130)
        at jdk.nashorn.tools.Shell.main(Shell.java:109)

        This was reported by Tal Liron @ nashorn-dev alias.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: