Menu

#2 problems using Jass

open
nobody
None
5
2007-10-18
2007-10-18
Anonymous
No

When I try to use Modern Jass I get the following error:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at jass.modern.core.compile.ContractJavaFile$ContractPrinter.visit(ContractJavaFile.java:214)
at jass.modern.core.compile.ContractJavaFile$ContractPrinter.visit(ContractJavaFile.java:1)
at jass.modern.core.model.impl.Type.accept(Type.java:99)
at jass.modern.core.compile.ContractJavaFile.<init>(ContractJavaFile.java:270)
at jass.modern.core.compile.ContractJavaCompiler.getCompilationTaskJava6(ContractJavaCompiler.java:239)
at jass.modern.core.apt.AnnotationProcessor.process(AnnotationProcessor.java:99)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:624)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:553)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:698)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
at com.sun.tools.javac.main.Main.compile(Main.java:353)
at com.sun.tools.javac.main.Main.compile(Main.java:279)
at com.sun.tools.javac.main.Main.compile(Main.java:270)
at com.sun.tools.javac.Main.compile(Main.java:69)
at com.sun.tools.javac.Main.main(Main.java:54)

I use it in the following form:

javac -cp .:jass.modern.core-20070519.jar File.java

where File.java is some file annotated with JML like sintax, even with the sample in "Getting Started" happends this..

Any idea of what I forgot?

Discussion

  • Nobody/Anonymous

    Yes, I know that this post is 1 year old but I will contribute with my 5 cents.

    The error is due to the fact that jass expect the classes to belong to a package. Therefore, if you (like me!) try to run the "Getting Started" example with the main class from the default package you will get the index out of range. In fact the problem is due to the following jass lines from jass.modern.core.compile.ContractJavaFile$ContractPrinter.visit:

    int len = -1 + element.getQualifiedName().length() - element.getSimpleName().length();
    String packageStr = element.getQualifiedName().substring(0, len);

    if the main class is in the default package (that is, is not under any package) the value for the variable len will be -1 thus the call to substring method in the following line will be ...substring(0,-1)

    Modern Jass User solution: create all your classes under a package

    I hope this helps somebody.

    Regards,

    Salvador

     
  • Nobody/Anonymous

    I get the same error when I don't use a package path like its done in the example files (package Foo).

    Is there any existing workaround?

     

Log in to post a comment.