Menu

#142 package/variable conflict not resolved correctly

None
closed
nobody
None
5
2018-08-02
2003-11-05
No

The following bug appears to have been introduced in
Beanshell 2.0b1:

In my tests for Beanshell I have the following test. I
define a class bsh.BSHArrayInitializerTest. In this I have
three inner classes, A, B, and C where A extends B and
C extends B. I interpret the following code:

public void testArrayInitializer() throws EvalError {
Interpreter.DEBUG = true;
Interpreter i = new Interpreter();
i.eval("new bsh.BSHArrayInitializerTest.B[] {new
bsh.BSHArrayInitializerTest.A(), new
bsh.BSHArrayInitializerTest.C()};");
}

This should pass without exception, and did in 1.2b1
(haven't tried in 1.3).

In the current CVS (2.0b1) it gives a UtilEvalError of
undefined variable or classname while evaluating
bsh.BSHArrayInitializerTest.A.

With debugging turned on the following stack trace is
printed. (v long). It looks like package vs variable name
resolution isn't happening properly.

Debug: Trying to load class: bsh.BSHArrayInitializerTest.B
// Debug: getClass(): bsh.BSHArrayInitializerTest.B not
found in NameSpace: global
(bsh.NameSpace@10d8ea)
// Debug: trying class: bsh.BSHArrayInitializerTest.B
// Debug: absoluteNonClass list hit: java.lang.bsh
// Debug: absoluteNonClass list hit: java.io.bsh
// Debug: absoluteNonClass list hit: java.util.bsh
// Debug: absoluteNonClass list hit: java.net.bsh
// Debug: absoluteNonClass list hit: java.awt.bsh
// Debug: absoluteNonClass list hit: java.awt.event.bsh
// Debug: absoluteNonClass list hit: javax.swing.bsh
// Debug: absoluteNonClass list hit:
javax.swing.event.bsh
// Debug: absoluteNonClass list hit: bsh
// Debug: getClass(): bsh not found in
NameSpace: global (bsh.NameSpace@10d8ea)
// Debug: Trying to load class:
bsh.BSHArrayInitializerTest
// Debug: Name call to getStaticField, class: class
bsh.BSHArrayInitializerTest, field:B
// Debug: field reflect error: bsh.ReflectError: No such
field: B
// Debug: Trying to load class:
bsh.BSHArrayInitializerTest$B
// Debug: array base type = class
bsh.BSHArrayInitializerTest$B
// Debug: trying to resolve variable: bsh
// Debug: resolved variable: bsh in namespace:
NameSpace: global (bsh.NameSpace@10d8ea)
// Debug: trying to resolve variable:
BSHArrayInitializerTest
bsh.UtilEvalError: Undefined variable or class name while
evaluating: bsh.BSHArrayInitializerTest.A
at bsh.Name.consumeNextObjectField(Unknown
Source)
at bsh.Name.toObject(Unknown Source)
at bsh.BSHAmbiguousName.toObject(Unknown
Source)
at bsh.BSHAllocationExpression.objectAllocation
(Unknown Source)
at bsh.BSHAllocationExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHArrayInitializer.eval(Unknown Source)
at bsh.BSHArrayDimensions.eval(Unknown
Source)
at bsh.BSHArrayDimensions.eval(Unknown
Source)
at bsh.BSHAllocationExpression.arrayAllocation
(Unknown Source)
at
bsh.BSHAllocationExpression.objectArrayAllocation
(Unknown Source)
at bsh.BSHAllocationExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at
bsh.BSHArrayInitializerTest.testArrayInitializer
(BSHArrayInitializerTest.java:23)
at java.lang.reflect.Method.invoke(Native
Method)
at junit.framework.TestCase.runTest
(TestCase.java:154)
at junit.framework.TestCase.runBare
(TestCase.java:127)
at junit.framework.TestResult$1.protect
(TestResult.java:106)
at junit.framework.TestResult.runProtected
(TestResult.java:124)
at junit.framework.TestResult.run
(TestResult.java:109)
at junit.framework.TestCase.run
(TestCase.java:118)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.swingui.TestRunner$16.run
(TestRunner.java:623)
Undefined variable or class name while evaluating:
bsh.BSHArrayInitializerTest.A : at Line: 1 : in file: inline
evaluation of: ``new bsh.BSHArrayInitializerTest.B[]
{new bsh.BSHArrayInitializerTest.A(), new bs . . . '' :
bsh .BSHArrayInitializerTest .A

at bsh.UtilEvalError.toEvalError(Unknown
Source)
at bsh.UtilEvalError.toEvalError(Unknown
Source)
at bsh.BSHAmbiguousName.toObject(Unknown
Source)
at bsh.BSHAllocationExpression.objectAllocation
(Unknown Source)
at bsh.BSHAllocationExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHArrayInitializer.eval(Unknown Source)
at bsh.BSHArrayDimensions.eval(Unknown
Source)
at bsh.BSHArrayDimensions.eval(Unknown
Source)
at bsh.BSHAllocationExpression.arrayAllocation
(Unknown Source)
at
bsh.BSHAllocationExpression.objectArrayAllocation
(Unknown Source)
at bsh.BSHAllocationExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at
bsh.BSHArrayInitializerTest.testArrayInitializer
(BSHArrayInitializerTest.java:23)
at java.lang.reflect.Method.invoke(Native
Method)
at junit.framework.TestCase.runTest
(TestCase.java:154)
at junit.framework.TestCase.runBare
(TestCase.java:127)
at junit.framework.TestResult$1.protect
(TestResult.java:106)
at junit.framework.TestResult.runProtected
(TestResult.java:124)
at junit.framework.TestResult.run
(TestResult.java:109)
at junit.framework.TestCase.run
(TestCase.java:118)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at junit.swingui.TestRunner$16.run
(TestRunner.java:623)

Discussion

  • nickl-

    nickl- - 2018-08-02
    • Group: -->
     
  • nickl-

    nickl- - 2018-08-02

    Ticket has been migrated to github.
    Please follow up on this over here: https://github.com/beanshell/beanshell/issues/280

     
  • nickl-

    nickl- - 2018-08-02
    • status: open --> closed
     
  • nickl-

    nickl- - 2018-08-02

    Ticket has been migrated to github.
    Please follow up on this over here: https://github.com/beanshell/beanshell/issues/280

     

Log in to post a comment.