Skip to content

Commit

Permalink
Issue #8810: DesignForExtension check crashes CheckStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
nrmancuso authored and romani committed Sep 10, 2020
1 parent 22d2cb8 commit f931c7b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ public void visitToken(DetailAST ast) {
&& canBeOverridden(ast)
&& (isNativeMethod(ast)
|| !hasEmptyImplementation(ast))
&& !hasIgnoredAnnotation(ast, ignoredAnnotations)) {
&& !hasIgnoredAnnotation(ast, ignoredAnnotations)
&& !ScopeUtil.isInRecordBlock(ast)) {
final DetailAST classDef = getNearestClassOrEnumDefinition(ast);
if (canBeSubclassed(classDef)) {
final String className = classDef.findFirstToken(TokenTypes.IDENT).getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,14 @@ public void testNativeMethods() throws Exception {
verify(checkConfig, getPath("InputDesignForExtensionNativeMethods.java"), expected);
}

@Test
public void testDesignForExtensionRecords() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(DesignForExtensionCheck.class);

final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig,
getNonCompilablePath("InputDesignForExtensionRecords.java"), expected);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//non-compiled with javac: Compilable with Java14
package com.puppycrawl.tools.checkstyle.checks.design.designforextension;

/* Config:
*
* default
*/
public record InputDesignForExtensionRecords(String string) { // ok

@Override
public String toString() {
return string + "my string!";
}
}

0 comments on commit f931c7b

Please sign in to comment.