diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositoryAotMetadataService.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositoryAotMetadataService.java
index abf59c8281..dcdfe53f0e 100644
--- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositoryAotMetadataService.java
+++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositoryAotMetadataService.java
@@ -32,6 +32,7 @@
import org.springframework.ide.vscode.boot.java.BuildCommandProvider;
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
import org.springframework.ide.vscode.commons.java.IJavaProject;
+import org.springframework.ide.vscode.commons.java.IProjectBuild;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
import org.springframework.ide.vscode.commons.util.FileObserver;
@@ -136,10 +137,29 @@ public DataRepositoryAotMetadataService(FileObserver fileObserver, JavaProjectFi
}
}
+ /**
+ * The project's build type, or null when it is not known.
+ *
+ * Not every project has a build this server can classify: the invisible project the language server
+ * creates for a plain folder has none, and neither does a project contributed by an importer that is
+ * neither Maven nor Gradle - {@code ClasspathUtil.createProjectBuild} then reports a build whose type
+ * is null. Switching on that throws, and the callers here are on the indexing path, where an
+ * exception costs a whole type its symbols.
+ */
+ private static String buildType(IJavaProject project) {
+ IProjectBuild build = project.getProjectBuild();
+ return build == null ? null : build.getType();
+ }
+
public Optional
+ * The answer has to be "no metadata" rather than an exception: the caller is the Spring Data
+ * repository indexer, which reaches this service for every query method that carries no
+ * {@code @Query}, and an exception there is caught per type - so the whole repository interface
+ * loses its symbols.
+ *
+ * @author Artem
+ */
+public class DataRepositoryAotMetadataServiceBuildTypeTest {
+
+ private final DataRepositoryAotMetadataService service = new DataRepositoryAotMetadataService(null, null, null);
+
+ @Test
+ void buildWithoutATypeYieldsNoMetadata() {
+ IJavaProject project = mock(IJavaProject.class);
+ when(project.getProjectBuild()).thenReturn(IProjectBuild.create(null, null));
+
+ assertEquals(Optional.empty(), service.getRepositoryMetadata(project, "com.example.UserRepository"));
+ }
+
+ @Test
+ void noBuildAtAllYieldsNoMetadata() {
+ IJavaProject project = mock(IJavaProject.class);
+ when(project.getProjectBuild()).thenReturn(null);
+
+ assertEquals(Optional.empty(), service.getRepositoryMetadata(project, "com.example.UserRepository"));
+ }
+}