Skip to content

Commit

Permalink
TIL: Illegal static declaration in inner class
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsamehsalah committed Nov 25, 2023
1 parent 61626b7 commit 4142606
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private static void fixLoggerVariableDeclaration(
public @Nullable Void visitMethodInvocation(
MethodInvocationTree methodTree, Name className) {
if (GET_LOGGER_METHOD.matches(methodTree, state)) {
ExpressionTree arg1 = methodTree.getArguments().get(0);
String argumentName = SourceCode.treeToString(arg1, state);
ExpressionTree arg = methodTree.getArguments().get(0);
String argumentName = SourceCode.treeToString(arg, state);

if (!className.contentEquals(argumentName)) {

Check warning on line 121 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 121 without causing a test to fail

removed conditional - replaced equality check with true (covered by 1 tests RemoveConditionalMutator_EQUAL_IF)
fixBuilder.merge(
SuggestedFix.replace(arg1, className + JavaFileObject.Kind.CLASS.extension));
SuggestedFix.replace(arg, className + JavaFileObject.Kind.CLASS.extension));
}
}
return super.visitMethodInvocation(methodTree, className);

Check warning on line 126 in error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Slf4jLogDeclaration.java

View workflow job for this annotation

GitHub Actions / pitest

A change can be made to line 126 without causing a test to fail

replaced return value with null for visitMethodInvocation (covered by 1 tests NullReturnValsMutator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ void replacement() {
"class A {",
" Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(A.class);",
"",
" class B {",
" static class B {",
" private Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(B.class);",
" }",
"",
" class C {",
" static class C {",
" private static Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(C.class);",
" }",
"",
" class D {",
" static class D {",
" static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(D.class);",
" }",
"",
" class E {",
" static class E {",
" private final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(E.class);",
" }",
"",
" class F {",
" static class F {",
" private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(F.class);",
" }",
"",
" class G {",
" static class G {",
" private static final Logger NOT_PROPER_LOGGER_NAME = LoggerFactory.getLogger(G.class);",
" }",
"",
" class H {",
" static class H {",
" private static final Logger LOGGER_WITH_WRONG_CLASS_AS_ARGUMENT =",
" LoggerFactory.getLogger(J.class);",
" }",
Expand All @@ -59,31 +59,31 @@ void replacement() {
"class A {",
" private static final Logger LOG = LoggerFactory.getLogger(A.class);",
"",
" class B {",
" static class B {",
" private static final Logger LOG = LoggerFactory.getLogger(B.class);",
" }",
"",
" class C {",
" static class C {",
" private static final Logger LOG = LoggerFactory.getLogger(C.class);",
" }",
"",
" class D {",
" static class D {",
" private static final Logger LOG = LoggerFactory.getLogger(D.class);",
" }",
"",
" class E {",
" static class E {",
" private static final Logger LOG = LoggerFactory.getLogger(E.class);",
" }",
"",
" class F {",
" static class F {",
" private static final Logger LOG = LoggerFactory.getLogger(F.class);",
" }",
"",
" class G {",
" static class G {",
" private static final Logger LOG = LoggerFactory.getLogger(G.class);",
" }",
"",
" class H {",
" static class H {",
" private static final Logger LOG = LoggerFactory.getLogger(H.class);",
" }",
"",
Expand Down

0 comments on commit 4142606

Please sign in to comment.