NPE on type parameter annotations for this #3732

Closed
maggu2810 opened this Issue Jan 16, 2017 · 7 comments

Comments

Projects
None yet
3 participants
@maggu2810
Contributor

maggu2810 commented Jan 16, 2017

  • /var/tmp $ javac Demo.java

(compiled without error)

  • /var/tmp $ cat Demo.java
package tmp.demo.checkstyle;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.ByteBuffer;

public class Demo {

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
    public @interface UnknownInitialization {
        Class<?> value() default Object.class;
    }

    /**
     * Function to demonstrate a Checkstyle bug.
     *
     * @param buffer dummy argument
     */
    public void foo(@UnknownInitialization(Demo.class) Demo this,final ByteBuffer buffer) {
        buffer.putInt(1);
    }

}
  • /var/tmp $ cat config.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">
    <module name="TreeWalker">
        <!-- Checks for Javadoc comments.                     -->
        <!-- See http://checkstyle.sf.net/config_javadoc.html -->
        <module name="JavadocMethod"/>
        <module name="JavadocType"/>
        <module name="JavadocVariable"/>
        <module name="JavadocStyle"/>
    </module>
</module>
  • /var/tmp $ java -jar ~/Downloads/checkstyle-7.4-all.jar -c config.xml Demo.java
Starting audit...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing Demo.java
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:293)
	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:211)
	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.javadoc.JavadocMethodCheck.removeMatchingParam(JavadocMethodCheck.java:824)
	at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.checkParamTags(JavadocMethodCheck.java:756)
	at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.checkComment(JavadocMethodCheck.java:499)
	at com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.processAST(JavadocMethodCheck.java:357)
	at com.puppycrawl.tools.checkstyle.checks.AbstractTypeAwareCheck.visitToken(AbstractTypeAwareCheck.java:154)
	at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:361)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:498)
	at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:303)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:182)
	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:78)
	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:314)
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:284)
	... 4 more
Checkstyle ends with 1 errors.

I would expect that a type parameter annotation for this works does not raise a NPE in the checker framework.
Such annotations are used e.g. if you try to use the Checker Framework stuff (https://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#initialization-checker).

@maggu2810

This comment has been minimized.

Show comment
Hide comment
@maggu2810

maggu2810 Jan 16, 2017

Contributor

Without an understanding about your source code, this is at least a workaround for the NPE: maggu2810@e91e37a

Contributor

maggu2810 commented Jan 16, 2017

Without an understanding about your source code, this is at least a workaround for the NPE: maggu2810@e91e37a

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jan 16, 2017

Member

The issue and the fix look valid to me.
The issue is with Java 8s 'receiver parameters'. They don't have a variable name, but the this literal. JavadocMethodCheck is trying to find only variable name parameters.

Member

rnveach commented Jan 16, 2017

The issue and the fix look valid to me.
The issue is with Java 8s 'receiver parameters'. They don't have a variable name, but the this literal. JavadocMethodCheck is trying to find only variable name parameters.

maggu2810 added a commit to maggu2810/checkstyle that referenced this issue Jan 16, 2017

fix NPE for Java 8's 'receiver parameter'
Fixes: checkstyle#3732
Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>

maggu2810 added a commit to maggu2810/checkstyle that referenced this issue Jan 16, 2017

@maggu2810

This comment has been minimized.

Show comment
Hide comment
@maggu2810

maggu2810 Jan 16, 2017

Contributor

Thanks @rnveach
I will create the PR after the approval label has been added.

Contributor

maggu2810 commented Jan 16, 2017

Thanks @rnveach
I will create the PR after the approval label has been added.

@maggu2810

This comment has been minimized.

Show comment
Hide comment
@maggu2810

maggu2810 Jan 17, 2017

Contributor

I found #3239 and it seems to be solved. Is this a regression or what is different here?

Contributor

maggu2810 commented Jan 17, 2017

I found #3239 and it seems to be solved. Is this a regression or what is different here?

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Jan 17, 2017

Member

@maggu2810 That was just adding the tokens to our antlr so we could identify and understand the java code syntax.

Member

rnveach commented Jan 17, 2017

@maggu2810 That was just adding the tokens to our antlr so we could identify and understand the java code syntax.

@romani romani added the approved label Jan 17, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jan 17, 2017

Member

Issue is approved.
All old javadoc Checks do not pass our regression testing, so quality is less than for other Checks.
Old javadoc checks unfortunately are error prone and fragile.
Please be welcome with PR.

Member

romani commented Jan 17, 2017

Issue is approved.
All old javadoc Checks do not pass our regression testing, so quality is less than for other Checks.
Old javadoc checks unfortunately are error prone and fragile.
Please be welcome with PR.

maggu2810 added a commit to maggu2810/checkstyle that referenced this issue Jan 25, 2017

romani added a commit that referenced this issue Jan 27, 2017

@romani romani added the bug label Jan 27, 2017

@romani romani added this to the 7.5 milestone Jan 27, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jan 27, 2017

Member

Fix is merged

Member

romani commented Jan 27, 2017

Fix is merged

@romani romani closed this Jan 27, 2017

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