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 8 Grammar: annotations on varargs parameters #3238

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

Java 8 Grammar: annotations on varargs parameters #3238

rnveach opened this issue Jun 2, 2016 · 8 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/9.

$ cat TestClass.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class TestClass {
    public void m5(@Nullable String @Nullable ... vararg) {}
}

@Target(ElementType.TYPE_USE)
@interface Nullable {
}

$ 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>
</module>

$ java -jar checkstyle-6.19-all.jar -c TestConfig.xml TestClass.java
Starting audit...
TestClass.java:5:47: unexpected token: ...
Audit done.

Input is compilable with java 8 javac.

@romani romani changed the title Java 8 Grammar: missing annotation 2 Java 8 Grammar: annotations on varargs parameters Jun 2, 2016
@romani
Copy link
Member

romani commented Jun 2, 2016

Input is compilable with java 8 javac.

next time please prove this in console output.

@romani
Copy link
Member

romani commented Jul 1, 2018

such syntax is now appeared at guava.

I am raising priority.

@strkkk
Copy link
Member

strkkk commented Jun 4, 2019

@romani @rnveach
I couldn't reproduce this in 8.20 version, probably it was fixed.

$ cat TestClass.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class TestClass {
    public void m5(@Nullable String @Nullable ... vararg) {}
}

@Target(ElementType.TYPE_USE)
@interface Nullable {
}

$ cat conf.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>
</module>

$ java -jar checkstyle-8.20-all.jar -c conf.xml TestClass.java
Starting audit...
Audit done.

@rnveach
Copy link
Member Author

rnveach commented Jun 4, 2019

@strkkk Some things in Checkstyle have changed since my initial report. TreeWalker does nothing if it doesn't have any children module. If you add a module or print the tree, you will see the exception still occurs.

com.puppycrawl.tools.checkstyle.api.CheckstyleException: IllegalStateException occurred while parsing file TestClass.java.
    at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:105)
    at com.puppycrawl.tools.checkstyle.JavaParser.parseFileText(JavaParser.java:121)
    at com.puppycrawl.tools.checkstyle.JavaParser.parseFile(JavaParser.java:140)
    at com.puppycrawl.tools.checkstyle.AstTreeStringPrinter.printJavaAndJavadocTree(AstTreeStringPrinter.java:76)
    at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:289)
    at com.puppycrawl.tools.checkstyle.Main.execute(Main.java:180)
    at com.puppycrawl.tools.checkstyle.Main.main(Main.java:119)
Caused by: java.lang.IllegalStateException: TestClass.java:5:47: unexpected token: ...
    at com.puppycrawl.tools.checkstyle.JavaParser$1.reportError(JavaParser.java:93)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinition(GeneratedJavaRecognizer.java:411)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:202)
    at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:99)
    ... 6 more
Caused by: TestClass.java:5:47: unexpected token: ...
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.annotation(GeneratedJavaRecognizer.java:1822)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.annotations(GeneratedJavaRecognizer.java:226)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classTypeSpec(GeneratedJavaRecognizer.java:826)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeSpec(GeneratedJavaRecognizer.java:780)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.variableLengthParameterDeclaration(GeneratedJavaRecognizer.java:4860)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.parameterDeclarationList(GeneratedJavaRecognizer.java:3844)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.field(GeneratedJavaRecognizer.java:3302)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classBlock(GeneratedJavaRecognizer.java:2542)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.classDefinition(GeneratedJavaRecognizer.java:634)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinitionInternal(GeneratedJavaRecognizer.java:556)
    at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinition(GeneratedJavaRecognizer.java:389)
    ... 8 more

@sanyarnd
Copy link

Issue is still present in 8.23

@frankbenoit
Copy link

Issue is still present in 8.24

@rnveach rnveach removed their assignment Sep 30, 2019
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Dec 27, 2019
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Dec 29, 2019
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Dec 30, 2019
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Dec 31, 2019
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 1, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 8, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 8, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 8, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 8, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 20, 2020
romani pushed a commit to esilkensen/checkstyle that referenced this issue Jan 22, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 23, 2020
esilkensen added a commit to esilkensen/checkstyle that referenced this issue Jan 24, 2020
@romani romani added this to the 8.29 milestone Jan 24, 2020
@romani
Copy link
Member

romani commented Jan 24, 2020

fix is merged

@romani
Copy link
Member

romani commented Feb 24, 2020

@esilkensen , please contact me in gitter chat or send me email.

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

5 participants