[Checkers] error message throws exception

Mahmood Ali mahmood at MIT.EDU
Fri Aug 8 02:53:43 EDT 2008


This seems to be a bug in the compiler, not in the framework.  For  
some reason, when printErrLine tries to print the pointer '^' in the  
last line, the position is off when a tab is used in the line.

The solution for now is to replace all tabs with '    '.  You can do  
that using the following command:

perl -pi -e 's/<tab>/    /g' `find java -name '*.java'`

Note that to insert tab in the shell you need to press 'C-v <tab>'.

When examining Log.printErrLine(int, PrintWriter), implemented as  
follows:

         int col = source.getColumnNumber(pos);

         printLines(writer, line);
         for (int i = 0; i < col - 1; i++) {
             writer.print((line.charAt(i) == '\t') ? "\t" : " ");
         }

It seems that getColumnNumber treats tabs as advancement of 8  
characters, while they are only one character in 'line' String.   
According to source.getColumnNumber, line is 104 characters long, but  
line.size() is 55.  col in the exception case is 67, hence the thrown  
exception.

Regards,
Mahmood

On Aug 8, 2008, at 2:03 AM, Telmo wrote:

> The currently committed version of javari causes the following stack  
> trace, when I run make check-javari-all, after some errors:
>
> An annotation processor threw an uncaught exception.
> Consult the following stack trace for details.
> java.lang.StringIndexOutOfBoundsException: String index out of  
> range: 55
>        at java.lang.String.charAt(String.java:687)
>        at com.sun.tools.javac.util.Log.printErrLine(Log.java:251)
>        at com.sun.tools.javac.util.Log.writeDiagnostic(Log.java:343)
>        at com.sun.tools.javac.util.Log.report(Log.java:306)
>        at  
> com 
> .sun.tools.javac.util.AbstractLog.mandatoryWarning(AbstractLog.java: 
> 135)
>        at  
> com 
> .sun 
> .tools 
> .javac.processing.JavacMessager.printMessage(JavacMessager.java:169)
>        at checkers.source.SourceChecker.message(SourceChecker.java: 
> 288)
>        at checkers.source.SourceChecker.report(SourceChecker.java:402)
>        at  
> checkers.basetype.BaseTypeVisitor.visitTypeCast(BaseTypeVisitor.java: 
> 429)
>        at  
> checkers.javari.JavariVisitor.visitTypeCast(JavariVisitor.java:64)
>        at  
> checkers.javari.JavariVisitor.visitTypeCast(JavariVisitor.java:21)
>        at com.sun.tools.javac.tree.JCTree 
> $JCTypeCast.accept(JCTree.java:1591)
>        at  
> com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:67)
> [...]
>
> It seems like it is trying to produce a warning and failing. This is  
> most likely caused by the test I tried to preserve when doing the  
> visitTypeCast at JavariVisitor, but I don't understand why I cannot  
> use it there. Why is that the case, or is it actually a framework bug?
>
> -Telmo
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080808/cf1ea703/attachment.htm 


More information about the checkers mailing list