Repository navigation
fix: remove unreachable null checks and declare real nullability - #267
Merged
Merged
Conversation
adityamparikh
force-pushed
the
fix/nullness-warnings
branch
from
October 14, 2026 19:13
f892dda to
57d0739
Compare
IntelliJ reported conditions that can never be true and null flows that the declared types did not allow. Each one was either a null check on an input that cannot be null, or a type that claimed non-null for a value that can be null. They are fixed in that order: - Null checks on required @McpToolParam/@McpArg parameters are removed. MCP SDK 2.0 validates tool arguments against the input schema before dispatch, and CompleteRequest/CompleteArgument reject a null argument or value in their constructors. The blank and empty checks stay. - Values that really can be null keep their checks and get the type that says so: optional prompt arguments (purpose, sample, sampleDocument), PromptText.optionalCodeBlock's content, missing NamedList entries (CollectionUtils getters take NamedList<?>), JSON nulls in JsonResponseParser's containers, YAML front-matter nulls in MarkdownDocumentCreator.addValue, and maxScore when scores were not requested. - SortClause.order is @nullable. The search tool documents it as optional, defaulting to asc, but the generated schema listed it as required, so a clause without an order was rejected before reaching the code that applies the default. Now only field is required. Tests that passed null to now-required parameters are removed (10). The two that pin a contract on purpose (the SDK rejecting a null completion value, the binder passing null for a missing solr.url) keep the null and suppress the warning. Other test fixes: @nullable on captured system properties, AssertJ isPositive() instead of unboxing nullable counters, @autoclose for the MCP client, assertions that were always true (required() || !required(), size() >= 0, non-null span timestamps) now check what their messages describe, and unused fields, mocks, throws clauses and an empty else are gone. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
adityamparikh
force-pushed
the
fix/nullness-warnings
branch
from
October 26, 2026 19:13
57d0739 to
855edd5
Compare
|
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.



Stacked on #269 (
./gradlew buildrunsbuildSrc's tests) and #266 (google-java-format): the first two commits here are those PRs, and only the top commit (fix: remove unreachable null checks and declare real nullability) is new.What
Fixes IntelliJ's nullness warnings across
src/mainandsrc/test, the conditions it reports as always true or always false, and the dead code next to them. Every warning was one of two things, and each kind gets its own fix:Null checks removed
Required
@McpToolParam/@McpArgparameters no longer null-check. MCP SDK 2.0 validates tool arguments against the input schema before dispatch.CompleteRequestandCompleteArgumentalso reject a null argument or value in their constructors. The blank and empty checks stay.Affected:
AliasService: create and delete aliasCollectionService:createCollection,completeCollection,extractCollectionName,isHandlerStatsEmptySchemaService: collection and list validationIndexingService: Markdown documents, prompt formatJsonDocumentCreatorandIndexingDocumentCreatorSearchService: sort clausesTypes corrected; checks kept
purpose,sample,sampleDocumentprompt arguments;PromptText.optionalCodeBlock(content)@McpArgsCollectionUtils.getLong/getFloat/getIntegernow takeNamedList<?>;extractSingleCacheInfo,fetchMetricsNamedList.getreturns null for a missing keyJsonResponseParsercontainers are@Nullable ObjectnullvaluesMarkdownDocumentCreator.addValue(@Nullable Object value)key:with no valueSearchResponse.maxScore,QueryStats.maxScoreSortClause.orderFor
NamedList, declaringNamedList<Object>told IntelliJ that values can't be null. Removing the check, as the quick-fix suggests, would turn a missing key into an NPE. IngetFloat, the next line isFloat.parseFloat(value.toString()). InextractSingleCacheInfo, a cache entry is always absent on Solr 10.SortClause.order: thesearchtool tells clientsorderis optional and defaults toasc. The generated input schema listed it as required, though, so the SDK rejected a sort clause without an order before the default was ever applied. With@Nullable, onlyfieldis required:Tests
solr.urlis absent. They keep the null and suppressDataFlowIssueon that method only.@Nullable, sinceSystem.getPropertyreturns null when unset. Test lists built with a null value areNamedList<@Nullable Object>.isPositive(), which also fails clearly on null. Float comparisons useisCloseTo.required() || !required()now checks thatcollectionis required and the othersearchparameters are optional.size() >= 0now checks that the_defaultconfigset has dynamic fields.SimpleSpannever returns null timestamps.McpClientIntegrationTestBaseuses@AutoCloseinstead of a manual null-guardedafterAll.DockerImageHttpIntegrationTestbuilds itsHttpClientinline and reads the base URL from the container.throws Exceptionclauses (37, two of them inHttpSecurityConfiguration), redundant casts, an emptyelse, and two Javadoc links to test classes that aren't accessible from where they're used.Not changed
@McpArg(required = false): IntelliJ calls these redundant defaults. The repo writesrequiredexplicitly on every parameter, because@McpToolParamand@McpArghave opposite defaults.SolrContainerDanglingJavadoc)getFirst(), expression lambdasVerification
./gradlew buildpasses, with all 455 tests run, none skipped or failed. That's style: format Java sources with google-java-format #266's 465 minus the 10 removed null tests.buildSrc's 12 tests run in the same build via build: run buildSrc's tests as part of the build #269. NullAway, which fails the build onsrc/main, accepts every new@Nullable.ConstantValueinspection run on all 37 changed files reports nothing. The same run flags the originalCollectionUtils.DataFlowIssueandNullableProblemsreproduce every original warning on the unedited files. On the changed files, the only hits are calls into signatures this PR changes, checked against their old declarations.🤖 Generated with Claude Code