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

Behavior of javax.script.SimpleScriptContext.getAttributesScope(String name) contradicts to spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • None
    • b53
    • generic
    • generic

      There are two issues.

      1. The spec for method javax.script.SimpleScriptContext.getAttributesScope(String name) says that method should return -1 if no attribute with the given name is defined in any scope.
      In fact, the method returns 0 in this case. Here is an example:

      ...
      final SimpleScriptContext ctx = new SimpleScriptContext();
      final String name = getClass().getName() + "#newkey";
      System.out.println("Expected: result=-1");
      System.out.println("Returned: result=" + ctx.getAttributesScope(name));
      ...

      2. Method getAttributesScope can not find the scope for attribute with the null value. Here is an example:

      ...
      final SimpleScriptContext ctx = new SimpleScriptContext();
      final String name = getClass().getName() + "#newkey";
      ctx.setAttribute(name, null, ScriptContext.ENGINE_SCOPE);
      System.out.println("Expected: result=" + ScriptContext.ENGINE_SCOPE);
      System.out.println("Returned: result=" + ctx.getAttributesScope(name));
      ...

      It seems such behavior should be clarified in the spec.
      -

            sundar Sundararajan Athijegannathan
            agavrilosunw Alexey Gavrilov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: