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

NoWhitespaceAfterCheck for some array initialization crashes Checkstyle #4557

Closed
denizarsan opened this Issue Jun 29, 2017 · 13 comments

Comments

Projects
None yet
6 participants
@denizarsan

denizarsan commented Jun 29, 2017

$ javac C.java

$ cat C.java

class C {
    int i = new int[]{1}[0];
}

$ cat config.xml

<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="NoWhitespaceAfter"/>
  </module>
</module>

$ java -jar checkstyle-7.8.2-all.jar -c config.xml C.java

Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing C.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:425)
        at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:359)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:174)
Caused by: java.lang.NullPointerException
        at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.getPositionAfter(NoWhitespaceAfterCheck.java:175)
        at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.visitToken(NoWhitespaceAfterCheck.java:133)
        at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:370)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:507)
        at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:312)
        at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:184)
        at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
        at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)
        at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)
        ... 4 more
Checkstyle ends with 1 errors.

The tool crashes with a NPE for the given config and class. The problem is the array-initialization expression that creates an array with concrete values (in this case "1") and then indexes into it.

Please let me know if you want me to help with fixing this.

Attention: suppressed at circleci by - checkstyle/contribution@284acd3

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jun 30, 2017

Member

@denizarsan Please don't report issues using snapshot version. It is unclear what commit you used or if you added any of your own custom code on top of it. Please use release versions and update your first post.

Feel free to provide us with a fix. I don't know how easy/hard this will be.

Member

rnveach commented Jun 30, 2017

@denizarsan Please don't report issues using snapshot version. It is unclear what commit you used or if you added any of your own custom code on top of it. Please use release versions and update your first post.

Feel free to provide us with a fix. I don't know how easy/hard this will be.

@rnveach rnveach added the approved label Jun 30, 2017

@denizarsan

This comment has been minimized.

Show comment
Hide comment
@denizarsan

denizarsan Jun 30, 2017

@rnveach I have updated my post. I'm using the latest release (7.8.2) from https://sourceforge.net/projects/checkstyle/files/checkstyle/

denizarsan commented Jun 30, 2017

@rnveach I have updated my post. I'm using the latest release (7.8.2) from https://sourceforge.net/projects/checkstyle/files/checkstyle/

@sergileon

This comment has been minimized.

Show comment
Hide comment
@sergileon

sergileon Aug 29, 2017

Contributor

I am on it

Contributor

sergileon commented Aug 29, 2017

I am on it

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 30, 2017

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 30, 2017

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 30, 2017

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 31, 2017

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 31, 2017

sergileon added a commit to sergileon/checkstyle that referenced this issue Aug 31, 2017

Vladlis added a commit that referenced this issue Aug 31, 2017

@Vladlis

This comment has been minimized.

Show comment
Hide comment
@Vladlis

Vladlis Aug 31, 2017

Member

checkstyle/contribution@284acd3 is still to be reverted

Member

Vladlis commented Aug 31, 2017

checkstyle/contribution@284acd3 is still to be reverted

@romani romani added the bug label Aug 31, 2017

@romani romani added this to the 8.3 milestone Aug 31, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Aug 31, 2017

Member

commit is reverted in contribution

Member

romani commented Aug 31, 2017

commit is reverted in contribution

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Aug 31, 2017

Member

I think this issue is fixed.

Member

romani commented Aug 31, 2017

I think this issue is fixed.

@romani romani closed this Aug 31, 2017

@Vladlis Vladlis reopened this Sep 1, 2017

@Vladlis

This comment has been minimized.

Show comment
Hide comment
@Vladlis

Vladlis Sep 1, 2017

Member
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing /pipeline/source/contribution/checkstyle-tester/src/main/java/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespaceafter/InputNoWhitespaceAfterArrayDeclarations.java
 at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:295)
 at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)
 at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)
 at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)
 ... 29 more
Caused by: java.lang.NullPointerException
 at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.getPositionAfter(NoWhitespaceAfterCheck.java:181)
 at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.visitToken(NoWhitespaceAfterCheck.java:139)

is caught by Wercker on checkstyle/sevntu-checkstyle job after uncommenting checkstyle/contribution@284acd3, @sergileon please investigate and fix
This might be another issue

Member

Vladlis commented Sep 1, 2017

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing /pipeline/source/contribution/checkstyle-tester/src/main/java/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespaceafter/InputNoWhitespaceAfterArrayDeclarations.java
 at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:295)
 at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)
 at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:252)
 at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)
 ... 29 more
Caused by: java.lang.NullPointerException
 at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.getPositionAfter(NoWhitespaceAfterCheck.java:181)
 at com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.visitToken(NoWhitespaceAfterCheck.java:139)

is caught by Wercker on checkstyle/sevntu-checkstyle job after uncommenting checkstyle/contribution@284acd3, @sergileon please investigate and fix
This might be another issue

@sergileon

This comment has been minimized.

Show comment
Hide comment
@sergileon

sergileon Sep 1, 2017

Contributor

i run job on the master and not see exception

Contributor

sergileon commented Sep 1, 2017

i run job on the master and not see exception

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Sep 1, 2017

Member

@Vladlis , I do not see problem on master wercker, please share link

Member

romani commented Sep 1, 2017

@Vladlis , I do not see problem on master wercker, please share link

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Sep 1, 2017

Member

I am closing issue, till smb show we exact and reproducible case

Member

romani commented Sep 1, 2017

I am closing issue, till smb show we exact and reproducible case

@romani romani closed this Sep 1, 2017

@msimko81

This comment has been minimized.

Show comment
Hide comment
@msimko81

msimko81 May 9, 2018

Hi, I have the same problem as described in the original bug request.

If I use the following initialization block, the checkstyle plugin fails with NPE:

int group = new int[] { 1, 2, 3, 4, 9 }[RandomUtils.nextInt(0, 4)];

Splitting the code to two lines is the workaround, checkstyle is happy with this:

int[] availableGroups = new int[] { 1, 2, 3, 4, 9 };
int group = availableGroups[RandomUtils.nextInt(0, 4)];

msimko81 commented May 9, 2018

Hi, I have the same problem as described in the original bug request.

If I use the following initialization block, the checkstyle plugin fails with NPE:

int group = new int[] { 1, 2, 3, 4, 9 }[RandomUtils.nextInt(0, 4)];

Splitting the code to two lines is the workaround, checkstyle is happy with this:

int[] availableGroups = new int[] { 1, 2, 3, 4, 9 };
int group = availableGroups[RandomUtils.nextInt(0, 4)];
@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani May 9, 2018

Member

please make sure you use checkstyle version 8.3 and above to run without exception.

Member

romani commented May 9, 2018

please make sure you use checkstyle version 8.3 and above to run without exception.

@msimko81

This comment has been minimized.

Show comment
Hide comment
@msimko81

msimko81 May 9, 2018

Thanks. I have used the default plugin referenced from gradle 4.6
By specifying the checkstyle tool version 8.10, everything works now.

msimko81 commented May 9, 2018

Thanks. I have used the default plugin referenced from gradle 4.6
By specifying the checkstyle tool version 8.10, everything works now.

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