Skip to content

Answer with no metadata when the project build type is unknown - #2003

Open
sorteam wants to merge 1 commit into
spring-projects:mainfrom
sorteam:data-repository-unknown-build-type
Open

sorteam wants to merge 1 commit into
spring-projects:mainfrom
sorteam:data-repository-unknown-build-type

Conversation

@sorteam

@sorteam sorteam commented Sep 22, 2026

Copy link
Copy Markdown

Fixes #2002.

DataRepositoryAotMetadataService switches on project.getProjectBuild().getType() in two places.
That type is null whenever the build cannot be classified - the invisible project the language server
creates for a plain folder, or a project contributed by an importer that is neither Maven nor Gradle -
and switching on null throws.

The throw lands on the indexing path. DataRepositoryIndexer.identifyQueryString reaches this service
for every query method that carries no @Query, and SpringIndexerJavaAstScanner.extractSafely
catches per type declaration, so the whole repository interface contributes nothing to the index:
no repository bean, none of its query methods. Everything else indexes normally, which is what makes
it easy to miss - the index looks healthy and the repositories are simply not in it. Measured on the
workspace where I hit this (116 projects, ~10.7k java files): 802 interfaces extend a Spring Data
repository, 391 of them declare at least one method without @Query, and the running server's heap
held 5023 beans with those repositories absent.

Change

A null-safe buildType(IJavaProject) used by both getRepositoryMetadata and
regenerateMetadataCommand; an unreadable type answers Optional.empty(), which is what both methods
already do for a type that is neither maven nor gradle. Behaviour for Maven and Gradle projects is
unchanged.

DataRepositoryAotMetadataServiceBuildTypeTest covers a build whose type is null and a project with
no build at all. Both fail with an NPE against the previous implementation.

Verification

I compiled the modified class and the test against the language server jar shipped in
vmware.vscode-spring-boot 2.5.2026092200 and read the emitted bytecode: getRepositoryMetadata now
returns Optional.empty() before it reaches String.hashCode(). I have not run the project's own
Maven build or test suite, so please treat the change as needing your CI.

RewriteRecipeRepository.createRewriteProjectParser switches on the same value and its default
already throws IllegalStateException("The project is neither Maven nor Gradle!"); a null type there
replaces that message with an NPE. Not touched here - say the word and I will add it.

…d type is unknown

DataRepositoryAotMetadataService finds a repository's AOT metadata file by
switching on the project's build type. That type is null whenever the build
cannot be classified: the invisible project the language server creates for a
plain folder has no build file, and neither does a project contributed by an
importer that is neither Maven nor Gradle, so ClasspathUtil.createProjectBuild
reports a build whose type is null - and switching on null throws.

The caller is the Spring Data repository indexer, reached for every query method
that carries no @query, and SpringIndexerJavaAstScanner catches per type
declaration. The whole repository interface then contributes nothing at all - no
repository bean, none of its query methods - while the rest of the index is
built normally, so the index looks healthy and the repositories are simply
absent from it.

Both switches in the class now read the type through a null-safe helper and
answer Optional.empty(), which is what they already do for a type they do not
recognise. Adds a test for a build with no type and for a project with no build.

Signed-off-by: Artem <sorteam@users.noreply.github.com>
@sorteam
sorteam force-pushed the data-repository-unknown-build-type branch from eaf20a6 to a6c2486 Compare September 22, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring Data repositories are dropped from the index when the project build is neither Maven nor Gradle (NPE in DataRepositoryAotMetadataService)

1 participant