From 1eaa6c6384f45e5a6a07d6b85e42ce9baeee21d7 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Thu, 1 Nov 2018 19:45:44 +0100 Subject: [PATCH] Fix NPE in MavenBuildSupport.java Signed-off-by: Snjezana Peco --- .../internal/managers/MavenBuildSupport.java | 2 +- .../maven/multimodule2/module1/pom.xml | 24 ++++++++++++++++ .../maven/multimodule2/module2/pom.xml | 24 ++++++++++++++++ .../projects/maven/multimodule2/pom.xml | 28 +++++++++++++++++++ .../managers/MavenBuildSupportTest.java | 8 ++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module1/pom.xml create mode 100644 org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module2/pom.xml create mode 100644 org.eclipse.jdt.ls.tests/projects/maven/multimodule2/pom.xml diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java index 61fd631cfb..f6ad1d8fd4 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java @@ -85,7 +85,7 @@ public void collectProjects(Collection projects, IProject project, IPr } projects.add(project); IMavenProjectFacade projectFacade = registry.create(project, monitor); - if ("pom".equals(projectFacade.getPackaging())) { + if (projectFacade != null && "pom".equals(projectFacade.getPackaging())) { List modules = projectFacade.getMavenProjectModules(); for (String module : modules) { IPath pomPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath().append(module).append("pom.xml"); diff --git a/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module1/pom.xml b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module1/pom.xml new file mode 100644 index 0000000000..963bebfbd2 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module1/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + foo.bar + module1 + 0.0.1-SNAPSHOT + jar + + foo.bar + multimodule2 + 0.0.1-SNAPSHOT + + + + + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module2/pom.xml b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module2/pom.xml new file mode 100644 index 0000000000..056bd43c84 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/module2/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + foo.bar + module2 + 0.0.1-SNAPSHOT + jar + + foo.bar + multimodule2 + 0.0.1-SNAPSHOT + + + + + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/pom.xml b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/pom.xml new file mode 100644 index 0000000000..4da29af653 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/maven/multimodule2/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + foo.bar + multimodule2 + 0.0.1-SNAPSHOT + pom + + foo.bar + invalid + 0.0.1-SNAPSHOT + + + module1 + module2 + + + + + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java index a6c40ae0b0..9c3dacca1c 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupportTest.java @@ -86,6 +86,14 @@ public void testCompileWithEclipseTychoJdt() throws Exception { testNonStandardCompilerId("compile-with-tycho-jdt"); } + @Test + public void testInvalidProjects() throws Exception { + IProject project = importMavenProject("multimodule2"); + Set projects = new LinkedHashSet<>(); + new MavenBuildSupport().collectProjects(projects, project, new NullProgressMonitor()); + assertEquals(projects.size(), 1); + } + @Test public void testMultipleProjects() throws Exception { IProject project = importMavenProject("multimodule");