[cleanup][misc] Fix all javac warnings in main sources - #26257
Open
aahmed-se wants to merge 1 commit into
Open
Conversation
`compileJava` emitted 77 warnings across ten modules, mostly deprecations left by the Netty 4.2, Jetty 12.1, Guava 33 and commons-lang3 3.20 upgrades — including Jetty's `onWebSocketClose(int, String)`, which is marked for removal. Moved to the successor APIs: Guava's `Duration` cache overloads, `RECVBUF_ALLOCATOR`, `ThreadLocalRandom.current()`, `MutableObject.get()`, the 4-arg `PersistentSubscription` constructor and Jetty's 3-arg `onWebSocketClose`. Dropped the `EPOLL_MODE` call that Netty 4.2 documents as a no-op. Where no successor exists, suppressed narrowly at the declaration with a reason. Added `compileOnly(swagger-annotations)` to the three modules that read `pulsar-client`'s `@Schema` annotations without the types on their compile classpath. `compileJava` is now warning-free and `sanityCheck` passes. Test sources still emit warnings; those are left for a separate change. Assisted-by: Claude Code (Opus 5) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
./gradlew compileJava --warning-mode allemits 77 javac warnings across ten modules on a cleanmaster. Almost all of them are deprecations left behind by the Netty 4.2, Jetty 12.1, Guava 33 andcommons-lang3 3.20 upgrades:
pulsar-client-admin-originalpulsar-client-v5pulsar-brokerpulsar-testclientpulsar-client-originalpulsar-proxypulsar-client-apipulsar-websocketpulsar-commonpulsar-package-coreTwo reasons to clean this up now rather than later:
Session.Listener.onWebSocketClose(int, String)for removal(
@Deprecated(since = "12.1.0", forRemoval = true)).AbstractWebSocketHandlerstill overrides it,so the WebSocket proxy stops receiving close callbacks the moment Jetty drops the method.
unknown enum constant RequiredMode.REQUIREDmessage, which drowns out anything genuinely newappearing in a PR's build log.
Modifications
1. Deprecated APIs moved to their documented successors. Each of these was checked against the
dependency's own sources rather than assumed:
CacheBuilder.expireAfterAccess/Write(long, TimeUnit)→ theDurationoverloads, in the 7 caches inNamespaceName,PackageName,PulsarClientImpl,AbstractMultiVersionReader,MultiVersionSchemaInfoProvider,ConsumerHandlerandSimpleLoadManagerImpl.PlatformDependent.threadLocalRandom()→ThreadLocalRandom.current()inPulsarServiceNameResolver. Netty's deprecated method body is literallyreturn ThreadLocalRandom.current();.ChannelOption.RCVBUF_ALLOCATOR→RECVBUF_ALLOCATORinBrokerServiceandProxyService(4 call sites). A pure rename — Netty declares the deprecated field as
= RECVBUF_ALLOCATOR, thesame object.
MutableObject.getValue()→get()inSystemTopicBasedTopicPoliciesService.PersistentSubscriptionconstructor → the 4-arg one, inPersistentTopic.The 5-arg version ignores
subscriptionPropertiesentirely (the cursor already carries them), sothis is behaviour-identical.
createPersistentSubscriptionkeeps its signature becauseBrokerTestInterceptoroverrides it; its javadoc now records that the parameter is unused.onWebSocketClose(int, String)→onWebSocketClose(int, String, Callback)inAbstractWebSocketHandler, completing the callback. The old override had to be removed ratherthan kept alongside the new one:
JettyWebSocketFrameHandlerFactorythrowsInvalidWebSocketException("Cannot use two versions of onWebSocketClose")for an endpoint thatdeclares both. Its
isOverriddencheck keys ongetDeclaringClass() != Session.Listener.class, sothe inherited default is correctly ignored once ours is gone.
EpollChannelOption.EPOLL_MODEcall inDirectProxyHandler. Netty 4.2 documents boththe option and the
EpollModeenum as no-ops ("Netty always uses level-triggered mode and so thismethod is just a no-op"), and level-triggered is exactly what zero-copy splice requires — so the
guarded block was dead code. The
proxyZeroCopyModeEnabledsplice path itself is untouched.2. One unchecked-generics fix.
ScalableTopicController.prunablebuilt aCompletableFuture<Boolean>[]from a stream, which is an unchecked array creation. It now collectsinto a
Listand keeps the same short-circuiting drain check.3. Narrow suppressions where no successor API exists — placed at the declaration, each with a
comment giving the reason:
intercept(...)inProducerBuilder/ConsumerBuilder/ReaderBuilder:@SafeVarargsisillegal on an abstract method, so the heap-pollution warning is suppressed on the interface
declaration. The implementations (
ConsumerBuilderImpl,ReaderBuilderImpl) already carry@SafeVarargson theirfinaloverrides.AuthenticationAdapterbridge must call v4's deprecated host-lessgetAuthData()in order toimplement v5's host-less
authData(); there is no non-deprecated v4 equivalent without a brokerhost.
TopicPoliciesService.registerListeneroverrides(
SystemTopicBased,MetadataStore,LegacyAware) are now@Deprecatedthemselves, matching theinterface method they implement.
4.
compileOnly(swagger-annotations)added to three modules — this is the 52-warning group.pulsar-client's configuration-data classes (ClientConfigurationDataand friends) carryruntime-retained
@Schema(requiredMode = REQUIRED)annotations.pulsar-client-admin,pulsar-client-v5andpulsar-testclientcompile against those class files without the annotationtypes on their compile classpath, so javac can't resolve the enum constant. Six other modules
(
pulsar-broker,pulsar-common,pulsar-client,pulsar-proxy,pulsar-websocket,pulsar-client-tools) already declare it exactly this way; this just extends the existing convention.No production code behaviour is intended to change anywhere in this PR.
Compatibility note:
AbstractWebSocketHandler.onWebSocketClosechanges signature. That class ispublicinpulsar-websocket, so an out-of-tree subclass overriding the 2-arg form would need thesame one-line migration — but Jetty forces this move regardless, and the method being overridden is
Jetty's listener callback rather than a Pulsar API. I have not ticked The public API below for this
reason; happy to reclassify if a reviewer sees it differently.
Verifying this change
(Please pick either of the following options)
This change is already covered by existing tests, such as:
ProxyPublishConsumeTest(18 tests) — the end-to-end WebSocket path against a real Jettyserver. This is the important one: it exercises endpoint registration (which is where a botched
onWebSocketClosemigration throwsInvalidWebSocketException) and real session closes.pulsar-websocketsuite (33 tests), includingAbstractWebSocketHandlerTest, whosedirect
onWebSocketClosecall was updated to passCallback.NOOP.NamespaceNameTest,PackageNameTest,PulsarServiceNameResolverTest(29 tests) — the GuavaDurationandThreadLocalRandomchanges.PersistentSubscriptionTest,CreateSubscriptionTest,ScalableTopicControllerTest,SimpleLoadManagerImplTest,ProxyTest,ProxyDisableZeroCopyTest(90 tests) — thePersistentSubscriptionconstructor, theprunablerewrite, the load-manager cache and the Nettychannel-option renames.
SystemTopicBasedTopicPoliciesServiceTest,LegacyAwareTopicPoliciesServiceTest,TopicPoliciesServiceDisableTest,InmemoryTopicPoliciesServiceServiceTest(27 tests) — theMutableObject.get()change sits on the namespace-cleanup path these cover.197 tests total, 0 failures and 0 errors. No new tests were added: every change is either a
like-for-like API swap or annotation-only, so there is no new behaviour to cover.
Build verification:
./gradlew compileJava --rerun-tasks --warning-mode all→ BUILD SUCCESSFUL with zero warnings(was 77).
./gradlew sanityCheck→ passes (license headers, checkstyle, and main and test compilation forevery module).
Two things a reviewer should know:
DirectProxyHandlerchange is not covered by a local test run. epoll is Linux-only, soproxyZeroCopyModeEnablednever engages on macOS andProxyDisableZeroCopyTestonly covers thedisabled path. The removal rests on Netty 4.2's own javadoc marking the option a no-op. CI on Linux
will exercise the zero-copy path.
compileTestJavatasks, mostlyunchecked conversions in Mockito stubs, plus the same swagger classpath issue in
pulsar-proxy'stests. Deliberately left out to keep this PR reviewable; happy to follow up separately.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Dependencies:
compileOnly(libs.swagger.annotations)is added topulsar-client-admin,pulsar-client-v5andpulsar-testclient. Nothing is added or upgraded at the project level — theartifact and its version already come from the version catalog and are already used by six other
modules. Because the scope is
compileOnly, it reaches neither the runtime classpath nor thepublished artifacts: I regenerated all three POMs with
generatePomFileForMavenPublicationandconfirmed
swaggerappears zero times in each. No distribution contents or LICENSE/NOTICE fileschange. Flagged only because the diff touches
build.gradle.ktsfiles.