From d64e4d9735b085c2ce2ea72eb8aad67101ed3301 Mon Sep 17 00:00:00 2001 From: Connor Worley Date: Sun, 3 Nov 2024 13:30:42 -0800 Subject: [PATCH] Enable experimental checks and fix errors --- build.gradle | 148 +++++++++++++++++- ...HttpServerLifecycleChannelHandlerTest.java | 2 +- .../zuul/message/ZuulMessageImplTest.java | 16 +- .../netflix/zuul/groovy/GroovyCompiler.java | 6 +- .../zuul/scriptManager/FilterVerifier.java | 1 + 5 files changed, 155 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 12bf172c4d..42c31dfc8d 100644 --- a/build.gradle +++ b/build.gradle @@ -66,19 +66,155 @@ subprojects { tasks.withType(JavaCompile).configureEach { dependencies { - errorprone "com.uber.nullaway:nullaway:latest.release" - errorprone "com.google.errorprone:error_prone_core:latest.release" + errorprone "com.uber.nullaway:nullaway:0.12.1" + errorprone "com.google.errorprone:error_prone_core:2.35.1" } options.errorprone { check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.WARN) option("NullAway:AnnotatedPackages", "com.netflix.zuul") -// Uncomment to automatically apply fixes for a check: -// -// errorproneArgs.addAll( + errorproneArgs.addAll( +// Uncomment to automatically apply fixes for a check. +// N.B: disables all other checks while enabled. // "-XepPatchChecks:UnnecessaryParentheses", // "-XepPatchLocation:IN_PLACE", -// ) + "-Xep:AutoFactoryAtInject", + "-Xep:BanClassLoader", + "-Xep:BanSerializableRead", + "-Xep:ClassName", + "-Xep:ComparisonContractViolated", + "-Xep:DeduplicateConstants", + "-Xep:DepAnn", + "-Xep:EmptyIf", + "-Xep:ExtendsAutoValue", + "-Xep:InjectMoreThanOneQualifier", + "-Xep:InsecureCryptoUsage", + "-Xep:IterablePathParameter", + "-Xep:LongLiteralLowerCaseSuffix", + "-Xep:MissingRuntimeRetention", + "-Xep:NoAllocation", + "-Xep:RefersToDaggerCodegen", + "-Xep:StaticOrDefaultInterfaceMethod", + "-Xep:StaticQualifiedUsingExpression", + "-Xep:SystemExitOutsideMain", + "-Xep:UseCorrectAssertInTests", + "-Xep:AnnotationPosition", + "-Xep:AssertFalse", + "-Xep:AssistedInjectAndInjectOnConstructors", + "-Xep:AvoidObjectArrays", + "-Xep:BinderIdentityRestoredDangerously", + "-Xep:BindingToUnqualifiedCommonType", + "-Xep:BuilderReturnThis", + "-Xep:CanIgnoreReturnValueSuggester", + "-Xep:CannotMockFinalClass", + "-Xep:CannotMockMethod", + "-Xep:CatchingUnchecked", + "-Xep:CheckedExceptionNotThrown", + "-Xep:ConstantPatternCompile", + "-Xep:DefaultLocale", + "-Xep:DifferentNameButSame", + "-Xep:EqualsBrokenForNull", + "-Xep:ExpectedExceptionChecker", + "-Xep:FloggerLogWithCause", + "-Xep:FloggerMessageFormat", + "-Xep:FloggerRedundantIsEnabled", + "-Xep:FloggerRequiredModifiers", + "-Xep:FloggerWithCause", + "-Xep:FloggerWithoutCause", + "-Xep:FunctionalInterfaceClash", + "-Xep:HardCodedSdCardPath", + "-Xep:IdentifierName", + "-Xep:InconsistentOverloads", + "-Xep:InitializeInline", + "-Xep:InterfaceWithOnlyStatics", + "-Xep:InterruptedExceptionSwallowed", + "-Xep:Interruption", + "-Xep:MissingDefault", + "-Xep:MockitoDoSetup", + "-Xep:MutableGuiceModule", + "-Xep:NonCanonicalStaticMemberImport", + "-Xep:NonFinalStaticField", + "-Xep:PreferJavaTimeOverload", + "-Xep:PreferredInterfaceType", + "-Xep:PrimitiveArrayPassedToVarargsMethod", + "-Xep:QualifierWithTypeUse", + "-Xep:RedundantOverride", + "-Xep:RedundantThrows", + "-Xep:StringFormatWithLiteral", + "-Xep:StronglyTypeByteString", + "-Xep:StronglyTypeTime", + "-Xep:SunApi", + "-Xep:SuppressWarningsWithoutExplanation", + "-Xep:SystemOut", + "-Xep:TestExceptionChecker", + "-Xep:ThrowSpecificExceptions", + "-Xep:TimeUnitMismatch", + "-Xep:TooManyParameters", + "-Xep:TransientMisuse", + "-Xep:TruthContainsExactlyElementsInUsage", + "-Xep:TryWithResourcesVariable", + "-Xep:UnescapedEntity", + "-Xep:UnnecessarilyFullyQualified", + "-Xep:UnnecessarilyUsedValue", + "-Xep:UnnecessarilyVisible", + "-Xep:UnnecessaryAnonymousClass", + "-Xep:UnnecessaryDefaultInEnumSwitch", + "-Xep:UnnecessaryFinal", + "-Xep:UnnecessaryOptionalGet", + "-Xep:UnnecessaryTestMethodPrefix", + "-Xep:UnsafeLocaleUsage", + "-Xep:UnusedException", + "-Xep:UrlInSee", + "-Xep:UsingJsr305CheckReturnValue", + "-Xep:Var", + "-Xep:Varifier", + "-Xep:YodaCondition", + "-Xep:AnnotationMirrorToString", + "-Xep:AnnotationValueToString", + "-Xep:BooleanParameter", + "-Xep:ClassNamedLikeTypeParameter", + "-Xep:ConstantField", + "-Xep:EqualsMissingNullable", + "-Xep:FieldCanBeFinal", + "-Xep:FieldCanBeLocal", + "-Xep:FieldCanBeStatic", + "-Xep:FieldMissingNullable", + "-Xep:ForEachIterable", + "-Xep:ImmutableMemberCollection", + "-Xep:ImmutableRefactoring", + "-Xep:ImmutableSetForContains", + "-Xep:ImplementAssertionWithChaining", + "-Xep:LambdaFunctionalInterface", + "-Xep:MethodCanBeStatic", + "-Xep:MissingBraces", + "-Xep:MixedArrayDimensions", + "-Xep:MultiVariableDeclaration", + "-Xep:MultipleTopLevelClasses", + "-Xep:PackageLocation", + "-Xep:ParameterComment", + "-Xep:ParameterMissingNullable", + "-Xep:PrivateConstructorForNoninstantiableModule", + "-Xep:PrivateConstructorForUtilityClass", + "-Xep:PublicApiNamedStreamShouldReturnStream", + "-Xep:RemoveUnusedImports", + "-Xep:ReturnMissingNullable", + "-Xep:ReturnsNullCollection", + "-Xep:ScopeOnModule", + "-Xep:SwitchDefault", + "-Xep:SymbolToString", + "-Xep:ThrowsUncheckedException", + "-Xep:TryFailRefactoring", + "-Xep:TypeParameterNaming", + "-Xep:TypeToString", + "-Xep:UngroupedOverloads", + "-Xep:UnnecessaryBoxedAssignment", + "-Xep:UnnecessaryBoxedVariable", + "-Xep:UnnecessarySetDefault", + "-Xep:UnnecessaryStaticImport", + "-Xep:UseEnumSwitch", + "-Xep:VoidMissingNullable", + "-Xep:WildcardImport", + ) } } diff --git a/zuul-core/src/test/java/com/netflix/netty/common/HttpServerLifecycleChannelHandlerTest.java b/zuul-core/src/test/java/com/netflix/netty/common/HttpServerLifecycleChannelHandlerTest.java index ede1a9e9d5..498d9ff512 100644 --- a/zuul-core/src/test/java/com/netflix/netty/common/HttpServerLifecycleChannelHandlerTest.java +++ b/zuul-core/src/test/java/com/netflix/netty/common/HttpServerLifecycleChannelHandlerTest.java @@ -42,7 +42,7 @@ final class AssertReasonHandler extends ChannelInboundHandlerAdapter { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { - assert evt instanceof CompleteEvent; + Truth.assertThat(evt).isInstanceOf(CompleteEvent.class); this.completeEvent = (CompleteEvent) evt; } diff --git a/zuul-core/src/test/java/com/netflix/zuul/message/ZuulMessageImplTest.java b/zuul-core/src/test/java/com/netflix/zuul/message/ZuulMessageImplTest.java index 21d3c66719..a0804f9b08 100644 --- a/zuul-core/src/test/java/com/netflix/zuul/message/ZuulMessageImplTest.java +++ b/zuul-core/src/test/java/com/netflix/zuul/message/ZuulMessageImplTest.java @@ -16,21 +16,19 @@ package com.netflix.zuul.message; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import com.netflix.zuul.context.SessionContext; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.DefaultHttpContent; import io.netty.handler.codec.http.DefaultLastHttpContent; import io.netty.handler.codec.http.HttpContent; -import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.*; + @ExtendWith(MockitoExtension.class) class ZuulMessageImplTest { private static final String TEXT1 = "Hello World!"; @@ -66,7 +64,7 @@ void testBufferBody2GetBody() { final String body = new String(msg.getBody()); assertTrue(msg.hasBody()); assertTrue(msg.hasCompleteBody()); - assertEquals("Hello World!", body); + assertEquals(TEXT1, body); assertEquals(0, msg.getHeaders().getAll("Content-Length").size()); } @@ -79,7 +77,7 @@ void testBufferBody3GetBody() { final String body = new String(msg.getBody()); assertTrue(msg.hasBody()); assertTrue(msg.hasCompleteBody()); - assertEquals("Hello World!", body); + assertEquals(TEXT1, body); assertEquals(0, msg.getHeaders().getAll("Content-Length").size()); } @@ -92,7 +90,7 @@ void testBufferBody3GetBodyAsText() { final String body = msg.getBodyAsText(); assertTrue(msg.hasBody()); assertTrue(msg.hasCompleteBody()); - assertEquals("Hello World!", body); + assertEquals(TEXT1, body); assertEquals(0, msg.getHeaders().getAll("Content-Length").size()); } diff --git a/zuul-groovy/src/main/java/com/netflix/zuul/groovy/GroovyCompiler.java b/zuul-groovy/src/main/java/com/netflix/zuul/groovy/GroovyCompiler.java index c9e93221a6..c8a43f61f8 100644 --- a/zuul-groovy/src/main/java/com/netflix/zuul/groovy/GroovyCompiler.java +++ b/zuul-groovy/src/main/java/com/netflix/zuul/groovy/GroovyCompiler.java @@ -18,11 +18,12 @@ import com.netflix.zuul.DynamicCodeCompiler; import groovy.lang.GroovyClassLoader; -import java.io.File; -import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; + /** * Groovy code compiler * User: mcohen @@ -48,6 +49,7 @@ public Class compile(String sCode, String sName) { /** * @return a new GroovyClassLoader */ + @SuppressWarnings("BanClassLoader") GroovyClassLoader getGroovyClassLoader() { return new GroovyClassLoader(); } diff --git a/zuul-groovy/src/main/java/com/netflix/zuul/scriptManager/FilterVerifier.java b/zuul-groovy/src/main/java/com/netflix/zuul/scriptManager/FilterVerifier.java index d59599341d..975c3214cc 100644 --- a/zuul-groovy/src/main/java/com/netflix/zuul/scriptManager/FilterVerifier.java +++ b/zuul-groovy/src/main/java/com/netflix/zuul/scriptManager/FilterVerifier.java @@ -78,6 +78,7 @@ void checkZuulFilterInstance(Object zuulFilter) throws InstantiationException { * compiles the Groovy source code * */ + @SuppressWarnings("BanClassLoader") public Class compileGroovy(String sFilterCode) throws CompilationFailedException { GroovyClassLoader loader = new GroovyClassLoader(); return loader.parseClass(sFilterCode);