Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Grammar: annotation before variable declaration #3236

Closed
rnveach opened this issue Jun 2, 2016 · 6 comments
Closed

Java Grammar: annotation before variable declaration #3236

rnveach opened this issue Jun 2, 2016 · 6 comments

Comments

@rnveach
Copy link
Member

rnveach commented Jun 2, 2016

Taken from PR #3230 when working on Issue #3033 from a run on OpenJDK 8 in test/tools/pack200/typeannos/TypeUseTarget.java.

$ cat TestClass.java
package test;

import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

public class TestClass {
    void method() {
        @B Object o = new @B String @B [3];
    }
}
@Target(ElementType.TYPE_USE)
@interface B { }

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="FinalLocalVariable" />
    </module>
</module>

$ java -jar checkstyle-6.19-all.jar -c TestConfig.xml TestClass.java
Starting audit...
TestClass.java:8:12: expecting "class", found 'Object'
TestClass.java:8:30: unexpected token: String
TestClass.java:8:40: unexpected token: [
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing TestClass.java
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:281)
    at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:196)
    at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:396)
    at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:330)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:161)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: MismatchedTokenException occurred during the analysis of file TestClass.java.
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:193)
    at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
    at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:301)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:271)
    ... 4 more
Caused by: TestClass.java:9:5: expecting EOF, found '}'
    at antlr.Parser.match(Parser.java:211)
    at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:211)
    at com.puppycrawl.tools.checkstyle.TreeWalker.parse(TreeWalker.java:440)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:175)
    ... 7 more
Checkstyle ends with 1 errors.

Input is compilable with java 8 javac.


https://github.com/wcm-io looks like using this syntax, all projects should be used to validate grammar update.

@checkstyle checkstyle deleted a comment from esilkensen Dec 21, 2019
@romani romani added this to the 8.29 milestone Jan 24, 2020
@romani
Copy link
Member

romani commented Jan 24, 2020

fix is merged , in scope of #7407 PR (#3238)

@romani romani closed this as completed Jan 24, 2020
@romani
Copy link
Member

romani commented Jan 25, 2020

@esilkensen ,

https://github.com/wcm-io looks like using this syntax, all projects should be used to validate grammar update.

we forgot to test fix on real code of users, please run some regression test on such projects, to make sure we do not have parse error any more.
@stefanseifert should be notified to activate checkstyle back if they still want it.
release of fix will be done tomorrow.

@esilkensen
Copy link
Member

Sounds good, I will do that and report back here soon.

@romani
Copy link
Member

romani commented Jan 25, 2020

Please do me extra favor and update https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/projects-to-test-on.properties#L15 to remove file TypeUseTarget.java from exclude that now is supported :) as you fixed parse issue.
(We have several copies of such file in this folder and multiple jdk lines)

@esilkensen
Copy link
Member

Here is a regression report comparing current master with the commit right before it: http://esilkensen.github.io/checkstyle-tester/3238-wcm-io/index.html

I will open a checkstyle-tester PR later today.

@romani
Copy link
Member

romani commented Jan 25, 2020

Looks good, looks like such project can use checkstyle.
It might be good to add such project to our list of test projects in contribution repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants