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

Exception during processing file ArrayClass.java:8:49: expecting IDENT, found 'int' #6064

Closed
zielint0 opened this issue Aug 9, 2018 · 15 comments
Labels
antlr approved has bounty issue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issues

Comments

@zielint0
Copy link

zielint0 commented Aug 9, 2018

D:\projects\untitled2\src>javac ArrayClass.java
D:\projects\untitled2\src>

/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!-- https://github.com/INRIA/spoon/blob/master/checkstyle.xml -->
<module name="Checker">
  <module name="TreeWalker">
    <module name="LeftCurly" />
  </module>
</module>

/var/tmp $ cat ArrayClass.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class ArrayClass {

	int[][][] i = new @TypeAnnotation(integer = 1) int[0][][];

	@Target({ ElementType.TYPE_USE })
	@interface TypeAnnotation {
		int integer() default 0;
	}
}

/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-X.XX-all.jar -c config.xml ArrayClass.java

D:\projects\spoon\src\test\java\spoon\test\arrays\testclasses\ArrayClass.java:8:49: expecting IDENT, found 'int'
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing src\test\java\spoon\test\arrays\testclasses\ArrayClass.java
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:295)
        at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)
        at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:581)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:472)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:226)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: MismatchedTokenException occurred while parsing file D:\projects\spoon\src\test\java\spoon\test\arrays\testclasses\ArrayClass.java.
        at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:98)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:180)
        at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:81)
        at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)
        ... 4 more
Caused by: D:\projects\spoon\src\test\java\spoon\test\arrays\testclasses\ArrayClass.java:10:2: expecting EOF, found 'int'
        at antlr.Parser.match(Parser.java:211)
        at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:211)
        at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:92)
        ... 8 more
Checkstyle ends with 1 errors.
PS D:\projects\spoon>


java -jar .\checkstyle-8.11-all.jar -c .\checkstyle.xml
ArrayClass.java

Checkstyle ended with exception.
It should provide list of code style violations
D:\projects\spoon\src\test\java\spoon\test\arrays\testclasses\ArrayClass.java:8:49: expecting IDENT, found 'int'


@checkstyle checkstyle deleted a comment from zielint0 Aug 13, 2018
@romani romani added the has bounty issue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issues label Apr 13, 2019
@nrmancuso
Copy link
Member

@romani, I wanted to take a look at this, but I can't reproduce it with newest master. I think we can mark this resolved.

@romani
Copy link
Member

romani commented Mar 20, 2020

To close issue we need CLI prove that it works.
@zielint0 , please recheck your side.

@nrmancuso
Copy link
Member

➜  Issue_6064 javac ArrayClass.java
➜  Issue_6064 cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!-- https://github.com/INRIA/spoon/blob/master/checkstyle.xml -->
<module name="Checker">
  <module name="TreeWalker">
    <module name="LeftCurly" />
  </module>
</module>
➜  Issue_6064 cat ArrayClass.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class ArrayClass {

	int[][][] i = new @TypeAnnotation(integer = 1) int[0][][];

	@Target({ ElementType.TYPE_USE })
	@interface TypeAnnotation {
		int integer() default 0;
	}
}
➜  Issue_6064 RUN_LOCALE="-Duser.language=en -Duser.country=US"
➜  Issue_6064 java $RUN_LOCALE -jar checkstyle-8.31-SNAPSHOT-all.jar -c config.xml ArrayClass.java 
Starting audit...
Audit done.

@romani
Copy link
Member

romani commented Mar 20, 2020

confirmed, resolved in 8.29

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

public class ArrayClass {

  int[][][] i = new @TypeAnnotation(integer = 1) int[0][][];

  @Target({ ElementType.TYPE_USE })
  @interface TypeAnnotation {
    int integer() default 0;
  }
}

$ java -jar /var/tmp/checkstyle-8.29-all.jar -c config.xml Test.java 
Starting audit...
Audit done.

@romani romani closed this as completed Mar 20, 2020
@romani
Copy link
Member

romani commented Mar 20, 2020

fixed by @esilkensen at #3238 or related.

but I think it will be honest to let @nmancus1 to claim a bounty in this issue as he found this issue and helped to close it.
@nmancus1 , when bountysource.com come back online please claim a bounty.

@nrmancuso
Copy link
Member

@romani that's very generous, thank you. Can you recommend another ANTLR issue that would be good for me?

@zielint0
Copy link
Author

Thank you for fixing this. Me and Spoon project are grateful :-)

@romani
Copy link
Member

romani commented Mar 20, 2020

@nmancus1 , I mentioned you in few issue , but can choose yourself at https://github.com/checkstyle/checkstyle/issues?q=is%3Aopen+is%3Aissue+label%3Aantlr

@romani
Copy link
Member

romani commented Mar 20, 2020

@zielint0 , to be honest I always wanted to try spoon , I never had a time to do this , but we try to apply all possible code analysis tool to your code, we have a lot of them already, but not a http://spoon.gforge.inria.fr/

I created #7913, I would appreciate if you help us start using it or explain in what validations checkstyle will benefit.

I will add spoon code to our testing projects, I hope we will not make exceptions on spoon code in future.

@zielint0
Copy link
Author

@romani
AFAIK Spoon is a Java library to low-level processing Java source code. You can for example use its API to detect empty catch blocks.

// file processors/CatchProcessor.java
package processors;

import org.apache.log4j.Level;
import spoon.processing.AbstractProcessor;
import spoon.reflect.code.CtCatch;

/**
 * Reports warnings when empty catch blocks are found.
 */
public class CatchProcessor extends AbstractProcessor<CtCatch> {
    public void process(CtCatch element) {
        // we get all statements and if there isn't statement, it means the block catch is empty!
        if (element.getBody().getStatements().size() == 0) {
            getFactory().getEnvironment().report(this, Level.WARN, element, "empty catch clause");
        }
    }
}

Spoon has no high-level checkers (like FinalClass, HideUtilityClassConstructor, InnerTypeLast in Checkstyle).

PVS-Studio is a static analysis tool that uses Spoon as a Java library for analyzing Java source code. Perhaps Checkstyle could use Spoon as an engine to overcome current limitations.

I think that you can also use Spoon to write some deep Spoon rules to analyze specific problems in Checkstyle Java source code (another words: write a mini static code analyzer for detecting problems in Checkstyle Java source code). However I don't know what would be useful. I use Checkstyle as an ordinary user, I don't develop Checkstyle per se.

@nrmancuso
Copy link
Member

@romani Bountysource appears to be back up, but I don't see this issue on there.

@romani romani reopened this Mar 21, 2020
@romani
Copy link
Member

romani commented Mar 21, 2020

@nmancus1 , issue reopened, there should be button "solve issue" , please try again.

@nrmancuso
Copy link
Member

Ok! Done.

@romani romani closed this as completed Mar 22, 2020
@romani
Copy link
Member

romani commented Mar 22, 2020

Please claim bounty

@nrmancuso
Copy link
Member

Claimed! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
antlr approved has bounty issue has some money incentive to fix it, https://www.bountysource.com/teams/checkstyle/issues
Projects
None yet
Development

No branches or pull requests

4 participants