Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2015-12-03 16:33:56 +0000
committerStephan Herrmann2015-12-05 16:26:35 +0000
commit10d9ee7d6cd7cd29aebe50986af8fcc7cd9d4e32 (patch)
tree5378e7c399a3d6fdac457bda32581e2e758a4223
parent83aa074d1edc1431b30e3bdffeaa5b8dd0bf1353 (diff)
downloadeclipse.jdt.core-10d9ee7d6cd7cd29aebe50986af8fcc7cd9d4e32.tar.gz
eclipse.jdt.core-10d9ee7d6cd7cd29aebe50986af8fcc7cd9d4e32.tar.xz
eclipse.jdt.core-10d9ee7d6cd7cd29aebe50986af8fcc7cd9d4e32.zip
Bug 466291: IAE on renaming the location for external annotation
attachment - immediate fix for the IllegalArgumentException Change-Id: I328ee3e14208dfe7577b5e1a83943f3d9d3fcb7b
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java151
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java87
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java15
3 files changed, 183 insertions, 70 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java
index 0e62994a15..a891bec2e5 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java
@@ -15,6 +15,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaModelMarker;
import org.eclipse.jdt.core.IPackageFragment;
@@ -424,75 +425,97 @@ public class ExternalAnnotations17Test extends ExternalAnnotations18Test {
// annotation file is empty
public void testBogusAnnotationFile1() throws Exception {
- myCreateJavaProject("TestLibs");
- String lib1Content =
- "package libs;\n" +
- "\n" +
- "public interface Lib1<T> {\n" +
- " public Lib1<T> getLib();\n" +
- "}\n";
- addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] {
- "/UnannotatedLib/libs/Lib1.java",
- lib1Content
- }, null);
- createFileInProject("annots/libs", "Lib1.eea",
- "");
+ LogListener listener = new LogListener();
+ try {
+ Platform.addLogListener(listener);
- // type check sources:
- IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null);
- ICompilationUnit cu = fragment.createCompilationUnit("Test1.java",
- "package tests;\n" +
- "import org.eclipse.jdt.annotation.*;\n" +
- "\n" +
- "import libs.Lib1;\n" +
- "\n" +
- "public class Test1 {\n" +
- " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" +
- " return stringLib.getLib();\n" +
- " }\n" +
- "}\n",
- true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
- CompilationUnit reconciled = cu.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
- IProblem[] problems = reconciled.getProblems();
- assertProblems(problems, new String[] {
- "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'",
- }, new int[] { 8 });
+ myCreateJavaProject("TestLibs");
+ String lib1Content =
+ "package libs;\n" +
+ "\n" +
+ "public interface Lib1<T> {\n" +
+ " public Lib1<T> getLib();\n" +
+ "}\n";
+ addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] {
+ "/UnannotatedLib/libs/Lib1.java",
+ lib1Content
+ }, null);
+ createFileInProject("annots/libs", "Lib1.eea",
+ "");
+
+ // type check sources:
+ IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null);
+ ICompilationUnit cu = fragment.createCompilationUnit("Test1.java",
+ "package tests;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "import libs.Lib1;\n" +
+ "\n" +
+ "public class Test1 {\n" +
+ " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" +
+ " return stringLib.getLib();\n" +
+ " }\n" +
+ "}\n",
+ true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
+ CompilationUnit reconciled = cu.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
+ IProblem[] problems = reconciled.getProblems();
+ assertProblems(problems, new String[] {
+ "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'",
+ }, new int[] { 8 });
+
+ assertEquals("number of log entries", 1, listener.loggedStatus.size());
+ final Throwable exception = listener.loggedStatus.get(0).getException();
+ assertEquals("logged message", "missing class header in annotation file", exception.getMessage());
+ } finally {
+ Platform.removeLogListener(listener);
+ }
}
// wrong class header
public void testBogusAnnotationFile2() throws Exception {
- myCreateJavaProject("TestLibs");
- String lib1Content =
- "package libs;\n" +
- "\n" +
- "public interface Lib1<T> {\n" +
- " public Lib1<T> getLib();\n" +
- "}\n";
- addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] {
- "/UnannotatedLib/libs/Lib1.java",
- lib1Content
- }, null);
- createFileInProject("annots/libs", "Lib1.eea",
- "type Lib1\n");
+ LogListener listener = new LogListener();
+ try {
+ Platform.addLogListener(listener);
- // type check sources:
- IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null);
- ICompilationUnit cu = fragment.createCompilationUnit("Test1.java",
- "package tests;\n" +
- "import org.eclipse.jdt.annotation.*;\n" +
- "\n" +
- "import libs.Lib1;\n" +
- "\n" +
- "public class Test1 {\n" +
- " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" +
- " return stringLib.getLib();\n" +
- " }\n" +
- "}\n",
- true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
- CompilationUnit reconciled = cu.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
- IProblem[] problems = reconciled.getProblems();
- assertProblems(problems, new String[] {
- "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'",
- }, new int[] { 8 });
+ myCreateJavaProject("TestLibs");
+ String lib1Content =
+ "package libs;\n" +
+ "\n" +
+ "public interface Lib1<T> {\n" +
+ " public Lib1<T> getLib();\n" +
+ "}\n";
+ addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] {
+ "/UnannotatedLib/libs/Lib1.java",
+ lib1Content
+ }, null);
+ createFileInProject("annots/libs", "Lib1.eea",
+ "type Lib1\n");
+
+ // type check sources:
+ IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null);
+ ICompilationUnit cu = fragment.createCompilationUnit("Test1.java",
+ "package tests;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "import libs.Lib1;\n" +
+ "\n" +
+ "public class Test1 {\n" +
+ " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" +
+ " return stringLib.getLib();\n" +
+ " }\n" +
+ "}\n",
+ true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
+ CompilationUnit reconciled = cu.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
+ IProblem[] problems = reconciled.getProblems();
+ assertProblems(problems, new String[] {
+ "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'",
+ }, new int[] { 8 });
+
+ assertEquals("number of log entries", 1, listener.loggedStatus.size());
+ final Throwable exception = listener.loggedStatus.get(0).getException();
+ assertEquals("logged message", "missing class header in annotation file", exception.getMessage());
+ } finally {
+ Platform.removeLogListener(listener);
+ }
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
index 01a76143b2..19c83637fe 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
@@ -12,8 +12,10 @@ package org.eclipse.jdt.core.tests.model;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import junit.framework.Test;
@@ -24,9 +26,12 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
@@ -91,6 +96,14 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
return false;
}
}
+
+ static class LogListener implements ILogListener {
+ List<IStatus> loggedStatus = new ArrayList<>();
+ public void logging(IStatus status, String plugin) {
+ this.loggedStatus.add(status);
+ }
+ }
+
protected IJavaProject project;
protected IPackageFragmentRoot root;
@@ -1332,4 +1345,78 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests {
")I]",
Arrays.toString(annotatedSign));
}
+
+ public void testBrokenConfig1() throws Exception {
+ LogListener listener = new LogListener();
+ try {
+ Platform.addLogListener(listener);
+
+ myCreateJavaProject("TestBrokenConfig1");
+ addLibraryWithExternalAnnotations(this.project, "lib1.jar", "/NoProject", new String[] {
+ "/UnannotatedLib/libs/Lib1.java",
+ "package libs;\n" +
+ "\n" +
+ "import java.util.Collection;\n" +
+ "import java.util.Iterator;\n" +
+ "\n" +
+ "public interface Lib1 {\n" +
+ " <T> Iterator<T> unconstrainedTypeArguments1(Collection<T> in);\n" +
+ " Iterator<String> unconstrainedTypeArguments2(Collection<String> in);\n" +
+ " <T> Iterator<? extends T> constrainedWildcards(Collection<? extends T> in);\n" +
+ " <T extends Collection<?>> T constrainedTypeParameter(T in);\n" +
+ "}\n",
+ "/UnannotatedLib/libs/Lib2.java",
+ "package libs;\n" +
+ "public interface Lib2 {\n" +
+ " String test(String s);\n" +
+ "}\n"
+ }, null);
+ IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null);
+ ICompilationUnit unit = fragment.createCompilationUnit("Test1.java",
+ "package tests;\n" +
+ "import org.eclipse.jdt.annotation.*;\n" +
+ "\n" +
+ "import java.util.Collection;\n" +
+ "import java.util.Iterator;\n" +
+ "\n" +
+ "import libs.Lib1;\n" +
+ "\n" +
+ "public class Test1 {\n" +
+ " Iterator<@NonNull String> test1(Lib1 lib, Collection<@Nullable String> coll) {\n" +
+ " return lib.unconstrainedTypeArguments1(coll);\n" +
+ " }\n" +
+ " Iterator<@NonNull String> test2(Lib1 lib, Collection<@Nullable String> coll) {\n" +
+ " return lib.unconstrainedTypeArguments2(coll);\n" +
+ " }\n" +
+ " Iterator<? extends @NonNull String> test3(Lib1 lib, Collection<String> coll) {\n" +
+ " return lib.constrainedWildcards(coll);\n" +
+ " }\n" +
+ " @NonNull Collection<String> test4(Lib1 lib, @Nullable Collection<String> in) {\n" +
+ " return lib.constrainedTypeParameter(in);\n" +
+ " }\n" +
+ "}\n",
+ true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
+ CompilationUnit reconciled = unit.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
+ IProblem[] problems = reconciled.getProblems();
+ assertEquals("number of problems", 4, problems.length);
+
+ // second class to test if problem is logged more than once
+ ICompilationUnit unit2 = fragment.createCompilationUnit("Test2.java",
+ "package tests;\n" +
+ "import libs.Lib2;\n" +
+ "\n" +
+ "public class Test2 {\n" +
+ " void test1(Lib2 lib) {\n" +
+ " lib.test(null);\n" +
+ " }\n" +
+ "}\n",
+ true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor());
+ CompilationUnit reconciled2 = unit2.reconcile(AST.JLS8, true, null, new NullProgressMonitor());
+ assertNoProblems(reconciled2.getProblems());
+
+ assertEquals("number of log entries", 0, listener.loggedStatus.size());
+ } finally {
+ Platform.removeLogListener(listener);
+ }
+ }
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
index 78cf856b8e..c01f34ebe0 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
@@ -364,7 +364,7 @@ private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyIniti
IClasspathEntry entry = javaProject.getClasspathEntryFor(getPath());
if (entry != null) {
IProject project = javaProject.getProject();
- IPath externalAnnotationPath = ClasspathEntry.getExternalAnnotationPath(entry, project, false);
+ IPath externalAnnotationPath = ClasspathEntry.getExternalAnnotationPath(entry, project, false); // unresolved for use in ExternalAnnotationTracker
if (externalAnnotationPath != null)
setupExternalAnnotationProvider(project, externalAnnotationPath, annotationZip, reader,
entryName.substring(0, entryName.length() - SuffixConstants.SUFFIX_CLASS.length));
@@ -384,11 +384,14 @@ private void setupExternalAnnotationProvider(IProject project, final IPath exter
{
// try resolve path within the workspace:
IWorkspaceRoot root = project.getWorkspace().getRoot();
- IResource resource = externalAnnotationPath.segmentCount() == 1
- ? root.getProject(externalAnnotationPath.lastSegment())
- : root.getFolder(externalAnnotationPath);
- if (!resource.exists())
- resource = root.getFile(externalAnnotationPath);
+ IResource resource;
+ if (externalAnnotationPath.segmentCount() == 1) {
+ resource = root.getProject(externalAnnotationPath.lastSegment());
+ } else {
+ resource = root.getFolder(externalAnnotationPath);
+ if (!resource.exists())
+ resource = root.getFile(externalAnnotationPath);
+ }
String resolvedPath;
if (resource.exists()) {
if (resource.isVirtual()) {

Back to the top