Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#472 Exception - expecting EOF still in version 4.3

_release_4.3
closed
Oliver Burn
5
4 days ago
2007-02-23
Harri
No

The following class causes an exception in checkstyle 4.3, at least with eclipse-cs 4.3.0 plugin:
package foo.bar;

import java.util.List;

interface Foo {
public <T> List<T> bar(T foobar);
}

public class CheckstyleBug {

public void foo() {
    Foo foo = new Foo() {
        public <T> List<T> bar(T foobar) {
            return null;
        }
    };
}

}

If the anonymous inner class is converted to a real class, the exception disappeares.

The log file contains:
!ENTRY com.atlassw.tools.eclipse.checkstyle 1 0 2007-02-23 16:41:09.342

!MESSAGE Checkstyle-Plugin: RecognitionException occured.

!STACK 0

D:\work...\src\test\java\foo\bar\CheckstyleBug.java:15:13: expecting EOF, found '}'

at antlr.Parser.match(Parser.java:211)

at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:210)

at com.puppycrawl.tools.checkstyle.TreeWalker.parse(TreeWalker.java:579)

at com.puppycrawl.tools.checkstyle.TreeWalker.parse(TreeWalker.java:542)

at com.puppycrawl.tools.checkstyle.TreeWalker.process(TreeWalker.java:243)

at com.puppycrawl.tools.checkstyle.TreeWalker.process(TreeWalker.java:590)

at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:239)

at com.atlassw.tools.eclipse.checkstyle.builder.Auditor.runAudit(Auditor.java:193)

at com.atlassw.tools.eclipse.checkstyle.builder.CheckstyleBuilder.handleBuildSelection(CheckstyleBuilder.java:341)

at com.atlassw.tools.eclipse.checkstyle.builder.CheckstyleBuilder.build(CheckstyleBuilder.java:212)

at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:603)

...

Discussion

  • Michal Dobisek
    Michal Dobisek
    2008-04-15

    Logged In: YES
    user_id=2063595
    Originator: NO

    I am getting the same error in Checkstyle 4.4 from this piece of code:

    public class CheckstyleBug {
    public static void main(String[] args) {
    int[] myArray = new int[] { , };
    System.out.println(myArray.length);
    }
    }

    Checkstyle aparently gets confused by the odd (but valid) expression "{ , };"

     
  • Tim Moore
    Tim Moore
    2009-02-19

    I'm still seeing the original bug with a generic method in Checkstyle 4.4.

     
  • rms
    rms
    2009-03-16

    There are 2 problems here.
    For the generics problem, in (line 2311 of mine) com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer, checkstyle-4.4, in the typeParameters method, it wants to read:
    if (!(isThereASingleGtToEmit()) && inputState.guessing == 0)
    rather than:
    if (!(isThereASingleGtToEmit()))

    For the second problem, there is a missing case: COMMA in the arrayInitializer method (line 4533 in mine).
    Adding:
    case:COMMA:
    {
    match(COMMA);
    break;
    }
    (in line 4621) works.

     
  • This is still present in 5.3. The following code reproduces the error:

    class CheckstyleIsBroken {

    void checkstyleIsBroken() {
        CheckstyleIsBroken borkage = new CheckstyleIsBroken() {
    
            <T extends CheckstyleIsBroken> T borked(T brokenness) {
                return brokenness;
            }
        };
    }
    

    }

     
  • Derek
    Derek
    2012-07-18

    We are looking into adopting checkstyle but hitting this on several classes as well (which will sadly prevent adoption). It would be awesome to get a new version out with the patch referenced from the previous comment applied (assuming it works of course).

     
  • Oliver Burn
    Oliver Burn
    2012-09-06

    Fixed in changeset: e67b3c4c6345