mirror of https://github.com/hyperledger/besu
build - Refactor Besu custom error prone dependency (#6692)
Move Besu custom error-prone checks into its own repository and use it as an external dependency. This allows to move to a newer version of Google errorprone checks as well while cleaning up build.gradle file. Key changes resulted due to this change: * String toLowerCase and toUpperCase to use Locale.ROOT as argument * Use interface such as List,Map or NavigatableMap instead of concrete class where appropriate. * Simplify StringBuilder to plain String * Suppress warnings where appropriate. ----- Signed-off-by: Usman Saleem <usman@usmans.info>pull/6823/head
parent
56e1844415
commit
e954537fcc
@ -1,9 +0,0 @@ |
||||
The creation of custom errorprone checkers was largely derived from: |
||||
* https://github.com/tbroyer/gradle-errorprone-plugin |
||||
* https://errorprone.info/docs/installation |
||||
* https://github.com/google/error-prone/wiki/Writing-a-check |
||||
|
||||
To allow for debugging from within intellij, the following must be added to the VM args |
||||
in the run/debug configuration (this assumes your gradle cache is at the default location under |
||||
your home): |
||||
-Xbootclasspath/p:${HOME}/.gradle/caches/./modules-2/files-2.1/com.google.errorprone/javac/9+181-r4173-1/bdf4c0aa7d540ee1f7bf14d47447aea4bbf450c5/javac-9+181-r4173-1.jar |
@ -1,70 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
// we use this config to get the path of the JDK 9 javac jar, to |
||||
// stick it in the bootclasspath when running tests |
||||
configurations.maybeCreate("epJavac") |
||||
|
||||
|
||||
apply plugin: 'java' |
||||
apply plugin: 'net.ltgt.errorprone' |
||||
|
||||
sourceCompatibility = 17 |
||||
targetCompatibility = 17 |
||||
|
||||
dependencies { |
||||
api 'org.slf4j:slf4j-api' |
||||
|
||||
annotationProcessor 'com.google.auto.service:auto-service' |
||||
|
||||
implementation 'com.google.auto.service:auto-service' |
||||
implementation 'com.google.errorprone:error_prone_annotation' |
||||
implementation 'com.google.errorprone:error_prone_core' |
||||
implementation 'info.picocli:picocli' |
||||
|
||||
testImplementation 'com.google.errorprone:error_prone_test_helpers' |
||||
testImplementation 'org.assertj:assertj-core' |
||||
testImplementation 'org.junit.jupiter:junit-jupiter' |
||||
// imported to get org.jetbrains.annotations.NotNull |
||||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib' |
||||
|
||||
epJavac 'com.google.errorprone:error_prone_check_api' |
||||
} |
||||
|
||||
test { testLogging { showStandardStreams = true } } |
||||
|
||||
|
||||
tasks.withType(JavaCompile) { |
||||
options.compilerArgs += [ |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', |
||||
'--add-exports', |
||||
'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' |
||||
] |
||||
} |
||||
|
||||
javadoc { enabled = false } |
@ -1,60 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
import static com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; |
||||
import static com.google.errorprone.matchers.Description.NO_MATCH; |
||||
import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod; |
||||
|
||||
import java.util.Map; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.common.collect.ImmutableMap; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.matchers.Matcher; |
||||
import com.sun.source.tree.ExpressionTree; |
||||
import com.sun.source.tree.MethodInvocationTree; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Some methods should not be used, make sure that doesn't happen.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class BannedMethod extends BugChecker implements MethodInvocationTreeMatcher { |
||||
|
||||
private static final ImmutableMap<Matcher<ExpressionTree>, String> BANNED_METHOD_LIST = |
||||
ImmutableMap.of( |
||||
staticMethod().onClass("com.google.common.base.Objects").withAnyName(), |
||||
"Do not use com.google.common.base.Objects methods, use java.util.Objects methods instead.", |
||||
staticMethod().onClass("org.junit.Assert"), |
||||
"Do not use junit assertions. Use assertj assertions instead.", |
||||
staticMethod().onClass("org.apache.logging.log4j.LogManager"), |
||||
"Do not use org.apache.logging.log4j.LogManager, use org.slf4j.LoggerFactory methods instead."); |
||||
|
||||
@Override |
||||
public Description matchMethodInvocation( |
||||
final MethodInvocationTree tree, final VisitorState state) { |
||||
for (final Map.Entry<Matcher<ExpressionTree>, String> entry : BANNED_METHOD_LIST.entrySet()) { |
||||
if (entry.getKey().matches(tree, state)) { |
||||
return buildDescription(tree).setMessage(entry.getValue()).build(); |
||||
} |
||||
} |
||||
return NO_MATCH; |
||||
} |
||||
} |
@ -1,59 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; |
||||
import com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.util.ASTHelpers; |
||||
import com.sun.source.tree.MethodInvocationTree; |
||||
import com.sun.source.tree.NewClassTree; |
||||
import com.sun.tools.javac.code.Symbol; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Do not create SecureRandom directly.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class DoNotCreateSecureRandomDirectly extends BugChecker |
||||
implements MethodInvocationTreeMatcher, NewClassTreeMatcher { |
||||
|
||||
@SuppressWarnings("TreeToString") |
||||
@Override |
||||
public Description matchMethodInvocation( |
||||
final MethodInvocationTree tree, final VisitorState state) { |
||||
if (tree.getMethodSelect().toString().equals("SecureRandom.getInstance")) { |
||||
return describeMatch(tree); |
||||
} |
||||
|
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
@Override |
||||
public Description matchNewClass(final NewClassTree tree, final VisitorState state) { |
||||
final Symbol sym = ASTHelpers.getSymbol(tree.getIdentifier()); |
||||
if (sym != null && sym.toString().equals("java.security.SecureRandom")) { |
||||
return describeMatch(tree); |
||||
} |
||||
|
||||
return Description.NO_MATCH; |
||||
} |
||||
} |
@ -1,44 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.sun.source.tree.MethodInvocationTree; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Do not invoke MessageDigest.getInstance directly.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class DoNotInvokeMessageDigestDirectly extends BugChecker |
||||
implements MethodInvocationTreeMatcher { |
||||
|
||||
@SuppressWarnings("TreeToString") |
||||
@Override |
||||
public Description matchMethodInvocation( |
||||
final MethodInvocationTree tree, final VisitorState state) { |
||||
if (tree.getMethodSelect().toString().equals("MessageDigest.getInstance")) { |
||||
return describeMatch(tree); |
||||
} |
||||
return Description.NO_MATCH; |
||||
} |
||||
} |
@ -1,69 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; |
||||
import static com.google.errorprone.matchers.Matchers.contains; |
||||
import static com.sun.source.tree.Tree.Kind.NULL_LITERAL; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.matchers.Matcher; |
||||
import com.sun.source.tree.MethodTree; |
||||
import com.sun.source.tree.ReturnTree; |
||||
import com.sun.source.tree.Tree; |
||||
|
||||
/* |
||||
* This is reworked from an example found at: |
||||
* https://github.com/google/error-prone/wiki/Writing-a-check
|
||||
*/ |
||||
|
||||
@AutoService(BugChecker.class) // the service descriptor
|
||||
@BugPattern( |
||||
summary = "Do not return null optionals.", |
||||
severity = SUGGESTION, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class DoNotReturnNullOptionals extends BugChecker implements MethodTreeMatcher { |
||||
|
||||
private static class ReturnNullMatcher implements Matcher<Tree> { |
||||
|
||||
@Override |
||||
public boolean matches(final Tree tree, final VisitorState state) { |
||||
if ((tree instanceof ReturnTree) && (((ReturnTree) tree).getExpression() != null)) { |
||||
return ((ReturnTree) tree).getExpression().getKind() == NULL_LITERAL; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
private static final Matcher<Tree> RETURN_NULL = new ReturnNullMatcher(); |
||||
private static final Matcher<Tree> CONTAINS_RETURN_NULL = contains(RETURN_NULL); |
||||
|
||||
@SuppressWarnings("TreeToString") |
||||
@Override |
||||
public Description matchMethod(final MethodTree tree, final VisitorState state) { |
||||
if ((tree.getReturnType() == null) |
||||
|| !tree.getReturnType().toString().startsWith("Optional<") |
||||
|| (tree.getBody() == null) |
||||
|| (!CONTAINS_RETURN_NULL.matches(tree.getBody(), state))) { |
||||
return Description.NO_MATCH; |
||||
} |
||||
return describeMatch(tree); |
||||
} |
||||
} |
@ -1,76 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
import javax.lang.model.element.AnnotationMirror; |
||||
import javax.lang.model.element.AnnotationValue; |
||||
import javax.lang.model.element.ExecutableElement; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.AnnotationTreeMatcher; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.util.ASTHelpers; |
||||
import com.sun.source.tree.AnnotationTree; |
||||
import com.sun.tools.javac.tree.JCTree; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Experimental options must be hidden and not present in the BesuCommand class.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class ExperimentalCliOptionMustBeCorrectlyDisplayed extends BugChecker |
||||
implements AnnotationTreeMatcher { |
||||
|
||||
@Override |
||||
public Description matchAnnotation(AnnotationTree tree, VisitorState state) { |
||||
final AnnotationMirror annotationMirror = ASTHelpers.getAnnotationMirror(tree); |
||||
if (annotationMirror.getAnnotationType().toString().equals("picocli.CommandLine.Option")) { |
||||
final Optional<? extends AnnotationValue> names = |
||||
getAnnotationValue(annotationMirror, "names"); |
||||
if (names.isPresent() && names.get().getValue().toString().contains("--X")) { |
||||
final JCTree.JCCompilationUnit compilation = |
||||
(JCTree.JCCompilationUnit) state.getPath().getCompilationUnit(); |
||||
if (compilation.getSourceFile().getName().endsWith("BesuCommand.java")) { |
||||
return describeMatch(tree); |
||||
} |
||||
final Optional<? extends AnnotationValue> isHidden = |
||||
getAnnotationValue(annotationMirror, "hidden"); |
||||
if (isHidden.isEmpty() || !((boolean) isHidden.get().getValue())) { |
||||
return describeMatch(tree); |
||||
} |
||||
} |
||||
} |
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
private Optional<? extends AnnotationValue> getAnnotationValue( |
||||
final AnnotationMirror annotationMirror, final String name) { |
||||
final Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = |
||||
annotationMirror.getElementValues(); |
||||
final Optional<? extends AnnotationValue> retValue = |
||||
elementValues.keySet().stream() |
||||
.filter(k -> k.getSimpleName().toString().equals(name)) |
||||
.map(elementValues::get) |
||||
.findAny(); |
||||
return retValue; |
||||
} |
||||
} |
@ -1,131 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
|
||||
import javax.lang.model.element.Modifier; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; |
||||
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.util.ASTHelpers; |
||||
import com.sun.source.tree.ClassTree; |
||||
import com.sun.source.tree.MethodTree; |
||||
import com.sun.source.tree.ModifiersTree; |
||||
import com.sun.source.tree.VariableTree; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Method input parameters must be final.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class MethodInputParametersMustBeFinal extends BugChecker |
||||
implements MethodTreeMatcher, ClassTreeMatcher { |
||||
|
||||
private boolean isAbstraction = false; |
||||
private boolean isGenerated = false; |
||||
|
||||
@Override |
||||
public Description matchClass(final ClassTree tree, final VisitorState state) { |
||||
isAbstraction = |
||||
isInterface(tree.getModifiers()) |
||||
|| isAnonymousClassInAbstraction(tree) |
||||
|| isEnumInAbstraction(tree); |
||||
isGenerated = ASTHelpers.hasDirectAnnotationWithSimpleName(tree, "Generated"); |
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
@Override |
||||
public Description matchMethod(final MethodTree tree, final VisitorState state) { |
||||
if (isGenerated) { |
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
final ModifiersTree mods = tree.getModifiers(); |
||||
|
||||
if (isAbstraction) { |
||||
if (isConcreteMethod(mods)) { |
||||
return matchParameters(tree); |
||||
} |
||||
} else if (isNotAbstract(mods)) { |
||||
return matchParameters(tree); |
||||
} |
||||
|
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
private Description matchParameters(final MethodTree tree) { |
||||
for (final VariableTree inputParameter : tree.getParameters()) { |
||||
if (isMissingFinalModifier(inputParameter)) { |
||||
return describeMatch(tree); |
||||
} |
||||
} |
||||
|
||||
return Description.NO_MATCH; |
||||
} |
||||
|
||||
private boolean isMissingFinalModifier(final VariableTree inputParameter) { |
||||
return !inputParameter.getModifiers().getFlags().contains(Modifier.FINAL); |
||||
} |
||||
|
||||
private boolean isNotAbstract(final ModifiersTree mods) { |
||||
return !mods.getFlags().contains(Modifier.ABSTRACT); |
||||
} |
||||
|
||||
@SuppressWarnings("TreeToString") |
||||
private boolean isInterface(final ModifiersTree mods) { |
||||
return mods.toString().contains("interface"); |
||||
} |
||||
|
||||
private boolean isConcreteMethod(final ModifiersTree mods) { |
||||
return mods.getFlags().contains(Modifier.DEFAULT) || mods.getFlags().contains(Modifier.STATIC); |
||||
} |
||||
|
||||
private boolean isAnonymousClassInAbstraction(final ClassTree tree) { |
||||
return isAbstraction && isAnonymousClass(tree); |
||||
} |
||||
|
||||
private boolean isAnonymousClass(final ClassTree tree) { |
||||
return tree.getSimpleName().contentEquals(""); |
||||
} |
||||
|
||||
private boolean isEnumInAbstraction(final ClassTree tree) { |
||||
return isAbstraction && isEnum(tree); |
||||
} |
||||
|
||||
@SuppressWarnings("TreeToString") |
||||
private boolean isEnum(final ClassTree tree) { |
||||
return tree.toString().contains("enum"); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
// isAbstract and isGenerated are transient calculations, not relevant to equality checks
|
||||
if (this == o) return true; |
||||
if (o == null || getClass() != o.getClass()) return false; |
||||
return super.equals(o); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
// isAbstract and isGenerated are transient calculations, not relevant to equality checks
|
||||
return super.hashCode(); |
||||
} |
||||
} |
@ -1,75 +0,0 @@ |
||||
/* |
||||
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. |
||||
* Copyright Hyperledger Besu contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
/* Derived from https://github.com/palantir/gradle-baseline/blob/6fe385a80291473e7fc1441f176454bec4184d6b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/PreferCommonAnnotations.java */ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.BugPattern.SeverityLevel; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.ImportTreeMatcher; |
||||
import com.google.errorprone.fixes.SuggestedFix; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.util.ASTHelpers; |
||||
import com.sun.source.tree.ImportTree; |
||||
import com.sun.tools.javac.code.Type; |
||||
|
||||
/** |
||||
* Checker that recommends using the common version of an annotation. |
||||
* |
||||
* <p>Examples: - Guava's version of {@code @VisibleForTesting} over other copies. |
||||
*/ |
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Prefer the common version of annotations over other copies.", |
||||
severity = SeverityLevel.WARNING) |
||||
public final class PreferCommonAnnotations extends BugChecker implements ImportTreeMatcher { |
||||
|
||||
/** ClassName -> preferred import. */ |
||||
private static final Map<String, String> PREFERRED_IMPORTS = |
||||
Map.of("org.jetbrains.annotations.NotNull", "javax.annotation.Nonnull"); |
||||
|
||||
@Override |
||||
public Description matchImport(ImportTree tree, VisitorState state) { |
||||
Type importType = ASTHelpers.getType(tree.getQualifiedIdentifier()); |
||||
if (importType == null) { |
||||
return Description.NO_MATCH; |
||||
} |
||||
String importName = importType.toString(); |
||||
for (Map.Entry<String, String> entry : PREFERRED_IMPORTS.entrySet()) { |
||||
String affectedClassName = entry.getKey(); |
||||
String preferredType = entry.getValue(); |
||||
if (importName.endsWith(affectedClassName) && !Objects.equals(importName, preferredType)) { |
||||
SuggestedFix fix = |
||||
SuggestedFix.builder().removeImport(importName).addImport(preferredType).build(); |
||||
return this.buildDescription(tree) |
||||
.setMessage("Do not use " + importName + " use " + preferredType + " instead.") |
||||
.addFix(fix) |
||||
.build(); |
||||
} |
||||
} |
||||
return Description.NO_MATCH; |
||||
} |
||||
} |
@ -1,70 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; |
||||
import static com.google.errorprone.fixes.SuggestedFixes.addModifiers; |
||||
import static com.google.errorprone.matchers.Description.NO_MATCH; |
||||
import static com.google.errorprone.util.ASTHelpers.getType; |
||||
import static com.google.errorprone.util.ASTHelpers.isSubtype; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
import javax.lang.model.element.ElementKind; |
||||
import javax.lang.model.element.Modifier; |
||||
|
||||
import com.google.auto.service.AutoService; |
||||
import com.google.errorprone.BugPattern; |
||||
import com.google.errorprone.VisitorState; |
||||
import com.google.errorprone.bugpatterns.BugChecker; |
||||
import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher; |
||||
import com.google.errorprone.fixes.SuggestedFix; |
||||
import com.google.errorprone.matchers.Description; |
||||
import com.google.errorprone.suppliers.Supplier; |
||||
import com.google.errorprone.suppliers.Suppliers; |
||||
import com.google.errorprone.util.ASTHelpers; |
||||
import com.sun.source.tree.VariableTree; |
||||
import com.sun.tools.javac.code.Symbol; |
||||
import com.sun.tools.javac.code.Type; |
||||
|
||||
@AutoService(BugChecker.class) |
||||
@BugPattern( |
||||
summary = "Logger classes should be private, static, and final.", |
||||
severity = WARNING, |
||||
linkType = BugPattern.LinkType.NONE) |
||||
public class PrivateStaticFinalLoggers extends BugChecker implements VariableTreeMatcher { |
||||
|
||||
static final Supplier<Type> ORG_SLF4J_LOGGER = Suppliers.typeFromString("org.slf4j.Logger"); |
||||
|
||||
@Override |
||||
public Description matchVariable(final VariableTree tree, final VisitorState state) { |
||||
final Symbol.VarSymbol sym = ASTHelpers.getSymbol(tree); |
||||
if (sym == null || sym.getKind() != ElementKind.FIELD) { |
||||
return NO_MATCH; |
||||
} |
||||
if (sym.getModifiers() |
||||
.containsAll(List.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL))) { |
||||
return NO_MATCH; |
||||
} |
||||
if (!isSubtype(getType(tree), ORG_SLF4J_LOGGER.get(state), state)) { |
||||
return NO_MATCH; |
||||
} |
||||
Optional<SuggestedFix> fixes = |
||||
addModifiers(tree, state, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL); |
||||
return buildDescription(tree) |
||||
.addFix(fixes.isPresent() ? fixes.get() : SuggestedFix.emptyFix()) |
||||
.build(); |
||||
} |
||||
} |
@ -1,39 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class BannedMethodTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = CompilationTestHelper.newInstance(BannedMethod.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void bannedMethodsPositiveCases() { |
||||
compilationHelper.addSourceFile("BannedMethodPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void bannedMethodsNegativeCases() { |
||||
compilationHelper.addSourceFile("BannedMethodNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class DoNotCreateSecureRandomDirectlyTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(DoNotCreateSecureRandomDirectly.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotCreateSecureRandomDirectlyPositiveCases() { |
||||
compilationHelper.addSourceFile("DoNotCreateSecureRandomDirectlyPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotCreateSecureRandomDirectlyNegativeCases() { |
||||
compilationHelper.addSourceFile("DoNotCreateSecureRandomDirectlyNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class DoNotInvokeMessageDigestDirectlyTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(DoNotInvokeMessageDigestDirectly.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotInvokeMessageDigestDirectlyPositiveCases() { |
||||
compilationHelper.addSourceFile("DoNotInvokeMessageDigestDirectlyPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotInvokeMessageDigestDirectlyNegativeCases() { |
||||
compilationHelper.addSourceFile("DoNotInvokeMessageDigestDirectlyNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class DoNotReturnNullOptionalsTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(DoNotReturnNullOptionals.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotReturnNullPositiveCases() { |
||||
compilationHelper.addSourceFile("DoNotReturnNullOptionalsPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void doNotReturnNullNegativeCases() { |
||||
compilationHelper.addSourceFile("DoNotReturnNullOptionalsNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,45 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class ExperimentalCliOptionMustBeCorrectlyDisplayedTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance( |
||||
ExperimentalCliOptionMustBeCorrectlyDisplayed.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void experimentalCliOptionMustBeHiddenPositiveCases() { |
||||
compilationHelper |
||||
.addSourceFile("ExperimentalCliOptionMustBeCorrectlyDisplayedPositiveCases.java") |
||||
.doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void experimentalCliOptionMustBeHiddenNegativeCases() { |
||||
compilationHelper |
||||
.addSourceFile("ExperimentalCliOptionMustBeCorrectlyDisplayedNegativeCases.java") |
||||
.doTest(); |
||||
} |
||||
} |
@ -1,54 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class MethodInputParametersMustBeFinalTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(MethodInputParametersMustBeFinal.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void methodInputParametersMustBeFinalPositiveCases() { |
||||
compilationHelper.addSourceFile("MethodInputParametersMustBeFinalPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void methodInputParametersMustBeFinalInterfacePositiveCases() { |
||||
compilationHelper |
||||
.addSourceFile("MethodInputParametersMustBeFinalInterfacePositiveCases.java") |
||||
.doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void methodInputParametersMustBeFinalNegativeCases() { |
||||
compilationHelper.addSourceFile("MethodInputParametersMustBeFinalNegativeCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void methodInputParametersMustBeFinalInterfaceNegativeCases() { |
||||
compilationHelper |
||||
.addSourceFile("MethodInputParametersMustBeFinalInterfaceNegativeCases.java") |
||||
.doTest(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
class PreferCommonAnnotationsTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(PreferCommonAnnotations.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
void preferCommonAnnotationsPositiveCases() { |
||||
compilationHelper.addSourceFile("PreferCommonAnnotationsPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
void preferCommonAnnotationsNegativeCases() { |
||||
compilationHelper.addSourceFile("PreferCommonAnnotationsNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.errorprone.CompilationTestHelper; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class PrivateStaticFinalLoggersTest { |
||||
|
||||
private CompilationTestHelper compilationHelper; |
||||
|
||||
@BeforeEach |
||||
public void setup() { |
||||
compilationHelper = |
||||
CompilationTestHelper.newInstance(PrivateStaticFinalLoggers.class, getClass()); |
||||
} |
||||
|
||||
@Test |
||||
public void privateStaticFinalLoggersPositiveCases() { |
||||
compilationHelper.addSourceFile("PrivateStaticFinalLoggersPositiveCases.java").doTest(); |
||||
} |
||||
|
||||
@Test |
||||
public void privateStaticFinalLoggersNegativeCases() { |
||||
compilationHelper.addSourceFile("PrivateStaticFinalLoggersNegativeCases.java").doTest(); |
||||
} |
||||
} |
@ -1,29 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
public class BannedMethodNegativeCases { |
||||
|
||||
public void callsObjectsEquals() throws Exception { |
||||
Objects.equals("1", "1"); |
||||
} |
||||
|
||||
public void callsObjectsHashCode() throws Exception { |
||||
Objects.hash("1", "1"); |
||||
} |
||||
} |
@ -1,50 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import com.google.common.base.Objects; |
||||
|
||||
public class BannedMethodPositiveCases { |
||||
|
||||
public void callsObjectsEquals() throws Exception { |
||||
// BUG: Diagnostic contains: Do not use com.google.common.base.Objects methods, use
|
||||
// java.util.Objects methods instead.
|
||||
Objects.equal("1", "1"); |
||||
} |
||||
|
||||
public void callsObjectsHashCode() throws Exception { |
||||
// BUG: Diagnostic contains: Do not use com.google.common.base.Objects methods, use
|
||||
// java.util.Objects methods instead.
|
||||
Objects.hashCode("1", "1"); |
||||
} |
||||
|
||||
public void usesJUnitAssertions() throws Exception { |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertEquals(1, 1); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertNotEquals(1, 2); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertTrue(true); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertFalse(false); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertNull(null); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertNotNull("foo"); |
||||
// BUG: Diagnostic contains: Do not use junit assertions. Use assertj assertions instead.
|
||||
org.junit.Assert.assertArrayEquals(new int[] {1}, new int[] {1}); |
||||
} |
||||
} |
@ -1,34 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.security.Provider; |
||||
import java.security.SecureRandom; |
||||
|
||||
public class DoNotCreateSecureRandomDirectlyNegativeCases { |
||||
|
||||
public void callsNonJRESecureRandomGetInstance() throws Exception { |
||||
TestSecureRandom.getInstance(""); |
||||
TestSecureRandom.getInstance("", ""); |
||||
TestSecureRandom.getInstance("", new Provider("", 0, "") {}); |
||||
} |
||||
|
||||
public void invokesNonJRESecureRandomConstructor() throws Exception { |
||||
new TestSecureRandom(); |
||||
} |
||||
|
||||
private class TestSecureRandom extends SecureRandom {} |
||||
} |
@ -1,41 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.security.Provider; |
||||
import java.security.SecureRandom; |
||||
|
||||
public class DoNotCreateSecureRandomDirectlyPositiveCases { |
||||
|
||||
public void callsSecureRandomGetInstance() throws Exception { |
||||
// BUG: Diagnostic contains: Do not create SecureRandom directly.
|
||||
SecureRandom.getInstance(""); |
||||
|
||||
// BUG: Diagnostic contains: Do not create SecureRandom directly.
|
||||
SecureRandom.getInstance("", ""); |
||||
|
||||
// BUG: Diagnostic contains: Do not create SecureRandom directly.
|
||||
SecureRandom.getInstance("", new Provider("", 0, "") {}); |
||||
} |
||||
|
||||
public void invokesSecureRandomConstructor() throws Exception { |
||||
// BUG: Diagnostic contains: Do not create SecureRandom directly.
|
||||
new SecureRandom(); |
||||
|
||||
// BUG: Diagnostic contains: Do not create SecureRandom directly.
|
||||
new SecureRandom(new byte[] {}); |
||||
} |
||||
} |
@ -1,26 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
|
||||
public class DoNotInvokeMessageDigestDirectlyNegativeCases { |
||||
|
||||
public void callsMessageDigestGetInstance() throws NoSuchAlgorithmException { |
||||
MessageDigest dig = null; |
||||
} |
||||
} |
@ -1,26 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
|
||||
public class DoNotInvokeMessageDigestDirectlyPositiveCases { |
||||
|
||||
public void callsMessageDigestGetInstance() throws NoSuchAlgorithmException { |
||||
// BUG: Diagnostic contains: Do not invoke MessageDigest.getInstance directly.
|
||||
MessageDigest dig = MessageDigest.getInstance("SHA-256"); |
||||
} |
||||
} |
@ -1,36 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.util.Optional; |
||||
import javax.annotation.Nullable; |
||||
|
||||
public class DoNotReturnNullOptionalsNegativeCases { |
||||
|
||||
public interface allInterfacesAreValid { |
||||
public Optional<Long> ExpectToBeOverridden(); |
||||
} |
||||
|
||||
public DoNotReturnNullOptionalsNegativeCases() {} |
||||
|
||||
public Optional<Long> doesNotReturnNull() { |
||||
return Optional.of(3L); |
||||
} |
||||
|
||||
@Nullable |
||||
public Optional<Long> returnsNullButAnnotatedWithNullable() { |
||||
return Optional.empty(); |
||||
} |
||||
} |
@ -1,35 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public class DoNotReturnNullOptionalsPositiveCases { |
||||
|
||||
// BUG: Diagnostic contains: Do not return null optionals.
|
||||
public Optional<Long> returnsNull() { |
||||
return null; |
||||
} |
||||
|
||||
// BUG: Diagnostic contains: Do not return null optionals.
|
||||
public Optional<Long> sometimesReturnsNull(boolean random) { |
||||
if (random) { |
||||
|
||||
return null; |
||||
} |
||||
return Optional.of(2L); |
||||
} |
||||
} |
@ -1,50 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import picocli.CommandLine; |
||||
|
||||
public class ExperimentalCliOptionMustBeCorrectlyDisplayedNegativeCases { |
||||
|
||||
@CommandLine.Option( |
||||
hidden = true, |
||||
names = {"--Xexperimental"}) |
||||
private String experimental = ""; |
||||
|
||||
@CommandLine.Option( |
||||
hidden = false, |
||||
names = {"--notExperimental"}) |
||||
private String notExperimental = ""; |
||||
|
||||
@CommandLine.Option(names = {"--notExperimental2"}) |
||||
private String notExperimental2 = ""; |
||||
|
||||
private class AnotherClass { |
||||
@CommandLine.Option(names = {"--notExperimentalInAnotherClass"}) |
||||
private String notExperimentalInAnotherClass = ""; |
||||
|
||||
@CommandLine.Option( |
||||
hidden = true, |
||||
names = {"--XexperimentalInAnotherClass"}) |
||||
private String experimentalInAnotherClass = ""; |
||||
} |
||||
|
||||
private class BesuCommand { |
||||
|
||||
@CommandLine.Option(names = {"--notExperimentalInBesuCommandClass"}) |
||||
private String notExperimentalInBesuCommandClass = ""; |
||||
} |
||||
} |
@ -1,41 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import picocli.CommandLine; |
||||
|
||||
public class ExperimentalCliOptionMustBeCorrectlyDisplayedPositiveCases { |
||||
|
||||
// BUG: Diagnostic contains: Experimental options must be hidden and not present in the
|
||||
// BesuCommand class.
|
||||
@CommandLine.Option( |
||||
hidden = false, |
||||
names = {"--Xexperimental"}) |
||||
private String experimental = ""; |
||||
|
||||
// BUG: Diagnostic contains: Experimental options must be hidden and not present in the
|
||||
// BesuCommand class.
|
||||
@CommandLine.Option(names = {"--Xexperimental2"}) |
||||
private String experimental2 = ""; |
||||
|
||||
private class BesuCommand { |
||||
|
||||
// BUG: Diagnostic contains: Experimental options must be hidden and not present in the
|
||||
// BesuCommand class.
|
||||
@CommandLine.Option(names = {"--XexperimentalInBesuCommandClass"}) |
||||
private String experimentalInBesuCommandClass = ""; |
||||
} |
||||
} |
@ -1,40 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import java.util.Observable; |
||||
import java.util.Observer; |
||||
|
||||
public interface MethodInputParametersMustBeFinalInterfaceNegativeCases { |
||||
|
||||
void parameterCannotBeFinal(int value); |
||||
|
||||
default void concreteMethod(final long value) {} |
||||
|
||||
static void anotherConcreteMethod(final double value) {} |
||||
|
||||
static Observer annonymousClass() { |
||||
return new Observer() { |
||||
@Override |
||||
public void update(final Observable o, final Object arg) {} |
||||
}; |
||||
} |
||||
|
||||
void methodAfterAnnonymousClass(int value); |
||||
|
||||
enum Status {} |
||||
|
||||
void methodAfterEnum(int value); |
||||
} |
@ -1,24 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
public interface MethodInputParametersMustBeFinalInterfacePositiveCases { |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
default void concreteMethod(int value) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
static void concreteStaticMethodsAreIncluded(int value) {} |
||||
} |
@ -1,63 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import javax.annotation.processing.Generated; |
||||
|
||||
public class MethodInputParametersMustBeFinalNegativeCases { |
||||
|
||||
public void noInputParameters() {} |
||||
|
||||
public void onlyPrimativeInputParameters(final long value) {} |
||||
|
||||
public void onlyObjectInputParameters(final Object value) {} |
||||
|
||||
public void mixedInputParameters(final Object value, final int anotherValue) {} |
||||
|
||||
public interface allInterfacesAreValid { |
||||
void parameterCannotBeFinal(int value); |
||||
} |
||||
} |
||||
|
||||
@Generated( |
||||
value = "test", |
||||
comments = "Every method is buggy, but ignored because the class has been tagged generated") |
||||
class MethodInputParametersMustBeFinalPositiveCasesBugGenerated1 { |
||||
|
||||
public void primativeInputMethod(int value) {} |
||||
|
||||
public void objectInputMethod(Object value) {} |
||||
|
||||
public void mixedInputMethod(Object value, int anotherValue) {} |
||||
|
||||
@Generated( |
||||
value = "test", |
||||
comments = "Every method is buggy, but ignored because the class has been tagged generated") |
||||
public abstract class abstractClassDefinition { |
||||
public void concreteMethodsAreIncluded(int value) {} |
||||
} |
||||
|
||||
public void varArgsInputMethod(String... value) {} |
||||
} |
||||
|
||||
@Generated( |
||||
value = "test", |
||||
comments = "Every method is buggy, but ignored because the class has been tagged generated") |
||||
class MethodInputParametersMustBeFinalPositiveCasesBugGenerated2 { |
||||
|
||||
public void mixedInputMethodFirstFinal(final Object value, int anotherValue) {} |
||||
|
||||
public void mixedInputMethodSecondFinal(Object value, final int anotherValue) {} |
||||
} |
@ -1,41 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
public class MethodInputParametersMustBeFinalPositiveCases { |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void primativeInputMethod(int value) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void objectInputMethod(Object value) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void mixedInputMethod(Object value, int anotherValue) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void mixedInputMethodFirstFinal(final Object value, int anotherValue) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void mixedInputMethodSecondFinal(Object value, final int anotherValue) {} |
||||
|
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void varArgsInputMethod(String... value) {} |
||||
|
||||
public abstract class abstractClassDefinition { |
||||
// BUG: Diagnostic contains: Method input parameters must be final.
|
||||
public void concreteMethodsAreIncluded(int value) {} |
||||
} |
||||
} |
@ -1,32 +0,0 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import javax.annotation.Nonnull; |
||||
|
||||
public class PreferCommonAnnotationsNegativeCases { |
||||
|
||||
@Nonnull |
||||
public String getFoo() { |
||||
return "Foo"; |
||||
} |
||||
|
||||
// Fully Qualified Name is the "escape hatch"
|
||||
@org.jetbrains.annotations.NotNull |
||||
public String getBar() { |
||||
return "Bar"; |
||||
} |
||||
} |
@ -1,27 +0,0 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
// BUG: Diagnostic contains: Do not use org.jetbrains.annotations.NotNull use
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
public class PreferCommonAnnotationsPositiveCases { |
||||
|
||||
@NotNull |
||||
public String getFoo() { |
||||
return "Foo"; |
||||
} |
||||
} |
@ -1,25 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class PrivateStaticFinalLoggersNegativeCases { |
||||
|
||||
private static final Logger LOG = |
||||
LoggerFactory.getLogger(PrivateStaticFinalLoggersNegativeCases.class); |
||||
} |
@ -1,25 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.errorpronechecks; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
public class PrivateStaticFinalLoggersPositiveCases { |
||||
|
||||
// BUG: Diagnostic contains: Logger classes should be private, static, and final.
|
||||
private final Logger LOG = LoggerFactory.getLogger(PrivateStaticFinalLoggersPositiveCases.class); |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue