Menu

Unexpected and unexplained exception in Haikufy.java

2013-04-12
2013-04-13
  • Carl van Denzen

    Carl van Denzen - 2013-04-12

    HaikuVM throws a runtime error. It would be nice if this exception was caught and would log in what string the error occurred.
    Right now I am not interested in the cause of the error, but merely in the improvement of HaikuVM software.

    Maybe something like this in Haikufy.java (the second try/catch is what I changed):

    static void adjustClasspathAndMainClass() throws IOException {
        JavaClass jc =getClassFile(mainclass);
    
        String pack = jc.getClassName().replace(".", "/");
        pack=new File(pack).getPath().replace("\\", "/");
        if (!mainclass.equals(pack)) {
            try {
                jc =getClassFile(pack);
            } catch (FileNotFoundException e) {
                classpath+=";"+mainclass.substring(0, mainclass.length()-pack.length());
            } catch (StringIndexOutOfBoundsException e1) {
                            String message="In \"classpath+=\";\"+mainclass.substring(0, mainclass.length()-pack.length());\""
                                    + ", mainclass="+mainclass+", mainclass.length="+mainclass.length()
                                    + ", pack="+pack+", pack.length()="+pack.length();
                            throw new StringIndexOutOfBoundsException(message);
                        }
            mainclass=pack;
        }
    }
    

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>echo # generating c file
    s

    generating c files

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>echo ###################

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>"""C:\Program Files\Java
    \jdk1.7.0_13""\bin\java.exe" "-Dhaikuvm.home=d:\downloads\HaikuVM-1.0.2\haikuVM\ bin\.." "-DCOMMAND_NAME=haikulink" -classpath "d:\downloads\HaikuVM-1.0.2\haiku
    VM\lib\pc\bcel-5.2.jar;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\pc\haikutools.jar"
    haikuvm.pc.tools.HaikuVM --bootclasspath "d:\downloads\HaikuVM-1.0.2\haikuVM\li
    b\haikuvm\bootstrap.jar;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\haikuRT.j
    ar;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\nxt\classes.jar" --classpath "." --boo
    tclasspath d:\downloads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\bootstrap.jar;d:\downl
    oads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\haikuRT.jar;d:\downloads\HaikuVM-1.0.2\ha
    ikuVM\lib\nxt\classes.jar --classpath . -v --Config leonardo -o BlinkWithThread.
    hex BlinkWithThread
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
    ex out of range: -17
    at java.lang.String.substring(String.java:1911)
    at haikuvm.pc.tools.Haikufy.adjustClasspathAndMainClass(Haikufy.java:257
    )
    at haikuvm.pc.tools.HaikuVM.haikulink(HaikuVM.java:268)
    at haikuvm.pc.tools.HaikuVM.main(HaikuVM.java:93)

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>if errorlevel 1 goto :er
    ror

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>echo ###################

    D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>echo # error while gener
    ating c files

    error while generating c files

     

    Last edit: Carl van Denzen 2013-04-12
    • Carl van Denzen

      Carl van Denzen - 2013-04-12

      The improved error message:
      D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial>"""C:\Program Files\Java
      \jdk1.7.0_13""\bin\java.exe" "-Dhaikuvm.home=d:\downloads\HaikuVM-1.0.2\haikuVM\ bin\.." "-DCOMMAND_NAME=haikulink" -classpath "d:\downloads\HaikuVM-1.0.2\haiku
      VM\lib\pc\bcel-5.2.jar;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\pc\haikufier.jar"
      haikuvm.pc.tools.HaikuVM --bootclasspath "d:\downloads\HaikuVM-1.0.2\haikuVM\lib
      \haikuvm\bootstrap.jar;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\haikuRT.ja
      r;d:\downloads\HaikuVM-1.0.2\haikuVM\lib\nxt\classes.jar" --classpath "." --boot
      classpath d:\downloads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\bootstrap.jar;d:\downlo
      ads\HaikuVM-1.0.2\haikuVM\lib\haikuvm\haikuRT.jar;d:\downloads\HaikuVM-1.0.2\hai
      kuVM\lib\nxt\classes.jar --classpath . -v --Config leonardo -o BlinkWithThread.h
      ex BlinkWithThread
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
      ex out of range: -17:In "classpath+=";"+mainclass.substring(0, mainclass.length(
      )-pack.length());", mainclass=BlinkWithThread, mainclass.length=15, pack=arduino
      /tutorial/BlinkWithThread, pack.length()=32
      at haikuvm.pc.tools.Haikufy.adjustClasspathAndMainClass(Haikufy.java:250
      )
      at haikuvm.pc.tools.HaikuVM.haikulink(HaikuVM.java:268)
      at haikuvm.pc.tools.HaikuVM.main(HaikuVM.java:93)

       
      • genom2

        genom2 - 2013-04-13

        Thank you for your remark. This is the kind of help I (or an open source project) need.

        It's fixed now and will come with version 1.0.3. Telling you something like this:
        "
        Exception in thread "main" java.io.FileNotFoundException:
        Current directory is: D:\NetbeansProjects\hobby\BlinkLed\src\arduino\tutorial\.
        File: 'arduino/tutorial/BlinkWithThread.class'
        not found in bootclasspath='.....'
        and classpath='.'
        Class files are searched with respect to their package prefix. Please, consider to change the current directory or classpath.
        "

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.