Skip to content

Commit

Permalink
Issue #3732: fix NPE for Java 8's 'receiver parameter'
Browse files Browse the repository at this point in the history
  • Loading branch information
maggu2810 authored and romani committed Jan 27, 2017
1 parent f91b1af commit 8e52504
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Expand Up @@ -694,7 +694,9 @@ private static List<DetailAST> getParameters(DetailAST ast) {
while (child != null) {
if (child.getType() == TokenTypes.PARAMETER_DEF) {
final DetailAST ident = child.findFirstToken(TokenTypes.IDENT);
returnValue.add(ident);
if (ident != null) {
returnValue.add(ident);
}
}
child = child.getNextSibling();
}
Expand Down
Expand Up @@ -591,4 +591,10 @@ public void testAllowToSkipOverriden() throws Exception {
};
verify(checkConfig, getPath("InputJavadocMethodsNotSkipWritten.java"), expected);
}

@Test
public void testJava8ReceiverParameter() throws Exception {
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputJavadocReceiverParameter.java"), expected);
}
}
@@ -0,0 +1,32 @@
package com.puppycrawl.tools.checkstyle.checks.javadoc;

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 InputJavadocReceiverParameter {

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface UnknownInitialization {
/**
* A dummy annotation to check Java 8's receiver parameter handling.
*
* @return a class
*/
Class<?> value() default Object.class;
}

/**
* Function to check handling of Java 8's receiver parameter.
*
* @param buffer dummy argument
*/
public void foo(@UnknownInitialization(InputJavadocReceiverParameter.class) InputJavadocReceiverParameter this,
final ByteBuffer buffer) {
buffer.putInt(1);
}

}

0 comments on commit 8e52504

Please sign in to comment.