#311 Binary commands, case problem (NoClassDefFoundError)

open
nobody
Parsing (77)
9
2014-11-09
2008-02-19
miguillo
No

I have this issue (source code and terminal dump below). (This is perhaps the same problem as bug #1447187). When adding new compiled commands with <code>importCommands(...)</code>, there is a case sensitiveness problem. If one type a the command with different case, Bsh believe it as found the command and try the instantiate it, but it can't.
<pre>
BeanShell 2.0b5 - by Pat Niemeyer (pat@pat.net)
bsh % echo("toto");
toto
bsh % Echo("toto");
Exception in thread "main" java.lang.NoClassDefFoundError: net/example/bugreport/commands/Echo (wrong name: net/example/bugreport/commands/echo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at bsh.classpath.ClassManagerImpl.classForName(ClassManagerImpl.java:217)
at bsh.NameSpace.getCommand(NameSpace.java:961)
at bsh.Name.invokeLocalMethod(Name.java:925)
at bsh.Name.invokeMethod(Name.java:804)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.Interpreter.run(Interpreter.java:465)
at net.example.bugreport.BugReport.main(BugReport.java:22)
</pre>
Same thing with debug activated:
<pre>
BeanShell 2.0b5 - by Pat Niemeyer (pat@pat.net)
bsh % debug();
// Debug: eval(String): getBshPrompt()
// Debug: eval: nameSpace = NameSpace: global (bsh.NameSpace@5afd29)
// Debug: Time to initialize interpreter: 0
// Debug: invokeLocalMethod: getBshPrompt
// Debug: trying to resolve variable: bsh
// Debug: resolved variable: bsh in namespace: NameSpace: getBshPrompt (bsh.NameSpace@1a2961b) (method)
// Debug: trying to resolve variable: prompt
// Debug: End of File!
bsh % echo("toto");
>PrimaryExpression
> MethodInvocation
> AmbigousName: echo
> Arguments
> PrimaryExpression
> Literal
// Debug: invokeLocalMethod: echo
// Debug: getCommand: echo
// Debug: searching for script: /net/example/bugreport/commands/echo.bsh
// Debug: searching for class: net.example.bugreport.commands.echo
// Debug: Trying to load class: net.example.bugreport.commands.echo
// Debug: invoke static Method
// Debug: getResolvedMethod cache MISS: class net.example.bugreport.commands.echo - invoke
// Debug: Searching for method: invoke( bsh.Interpreter, bsh.CallStack, java.lang.String ) in 'net.example.bugreport.commands.echo'
// Debug: Looking for most specific method: invoke
// Debug: cacheResolvedMethod putting: class net.example.bugreport.commands.echo public static void net.example.bugreport.commands.echo.invoke(bsh.Interpreter,bsh.CallStack,java.lang.String)
// Debug: Invoking method (entry): public static void net.example.bugreport.commands.echo.invoke(bsh.Interpreter,bsh.CallStack,java.lang.String) with args:
// Debug: args[0] = bsh.Interpreter@1ac3c08 type = class bsh.Interpreter
// Debug: args[1] = CallStack:
NameSpace: global (bsh.NameSpace@5afd29)
type = class bsh.CallStack
// Debug: args[2] = toto type = class java.lang.String
// Debug: Invoking method (after massaging values): public static void net.example.bugreport.commands.echo.invoke(bsh.Interpreter,bsh.CallStack,java.lang.String) with args:
// Debug: args[0] = bsh.Interpreter@1ac3c08 type = class bsh.Interpreter
// Debug: args[1] = CallStack:
NameSpace: global (bsh.NameSpace@5afd29)
type = class bsh.CallStack
// Debug: args[2] = toto type = class java.lang.String
toto
// Debug: eval(String): getBshPrompt()
// Debug: eval: nameSpace = NameSpace: global (bsh.NameSpace@5afd29)
// Debug: Time to initialize interpreter: 0
// Debug: invokeLocalMethod: getBshPrompt
// Debug: trying to resolve variable: bsh
// Debug: resolved variable: bsh in namespace: NameSpace: getBshPrompt (bsh.NameSpace@1c5c1) (method)
// Debug: trying to resolve variable: prompt
// Debug: End of File!
bsh % Echo("toto");
>PrimaryExpression
> MethodInvocation
> AmbigousName: Echo
> Arguments
> PrimaryExpression
> Literal
// Debug: invokeLocalMethod: Echo
// Debug: getCommand: Echo
// Debug: searching for script: /net/example/bugreport/commands/Echo.bsh
// Debug: searching for class: net.example.bugreport.commands.Echo
// Debug: Trying to load class: net.example.bugreport.commands.Echo
Exception in thread "main" java.lang.NoClassDefFoundError: net/example/bugreport/commands/Echo (wrong name: net/example/bugreport/commands/echo)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at bsh.classpath.ClassManagerImpl.classForName(ClassManagerImpl.java:217)
at bsh.NameSpace.getCommand(NameSpace.java:961)
at bsh.Name.invokeLocalMethod(Name.java:925)
at bsh.Name.invokeMethod(Name.java:804)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.Interpreter.run(Interpreter.java:465)
at net.example.bugreport.BugReport.main(BugReport.java:18)

</pre>

net/example/bugreport/BugReport.java:
<pre>
package net.example.bugreport;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;

import bsh.EvalError;
import bsh.Interpreter;

public class BugReport {
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintStream out = new PrintStream(System.out);
Interpreter interpreter = new Interpreter(in, out, out, true);
try {
interpreter
.eval("importCommands(\"net.example.bugreport.commands\")");
interpreter.run();
} catch (EvalError e) {
e.printStackTrace();

}

}
}
</pre>
net/example/bugreport/commands/echo.java (it's "echo", not "Echo"):
<pre>
package net.example.bugreport.commands;

import bsh.CallStack;
import bsh.Interpreter;

public class echo {
public static void invoke( Interpreter env, CallStack callstack, String string)
{
env.println(string);
}
}

</pre>
Specs: JRE 1.6.0_04

Discussion

  • miguillo

    miguillo - 2008-02-19
    • priority: 5 --> 9
     
  • miguillo

    miguillo - 2008-02-19

    BugReport.java

     
  • miguillo

    miguillo - 2008-02-19

    Logged In: YES
    user_id=244345
    Originator: YES

    File Added: BugReport.java

     
  • miguillo

    miguillo - 2008-02-19

    echo.java

     
  • miguillo

    miguillo - 2008-02-19

    Logged In: YES
    user_id=244345
    Originator: YES

    File Added: echo.java

     

Log in to post a comment.