View | Details | Raw Unified | Return to bug 258145 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java (-1 / +16 lines)
Lines 20-25 Link Here
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
21
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
23
import org.eclipse.jdt.internal.compiler.problem.*;
24
import org.eclipse.jdt.internal.compiler.problem.*;
24
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
25
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
25
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
26
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
Lines 390-396 Link Here
390
		IMarker marker = resource.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
391
		IMarker marker = resource.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
391
		int severity = problemSeverity.equals(JavaCore.WARNING) ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR;
392
		int severity = problemSeverity.equals(JavaCore.WARNING) ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR;
392
393
393
		ISourceRange range = javaElement == null ? null : javaElement.getNameRange();
394
		ISourceRange range = null;
395
		if (javaElement != null) {
396
			try {
397
				range = javaElement.getNameRange();
398
			} catch (JavaModelException e) {
399
				if (e.getJavaModelStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
400
					throw e;
401
				}
402
				if (!CharOperation.equals(javaElement.getElementName().toCharArray(), TypeConstants.PACKAGE_INFO_NAME)) {
403
					throw e;
404
				}
405
				// else silently swallow the exception as the synthetic interface type package-info has no
406
				// source range really. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=258145
407
			}
408
		}
394
		int start = range == null ? 0 : range.getOffset();
409
		int start = range == null ? 0 : range.getOffset();
395
		int end = range == null ? 1 : start + range.getLength();
410
		int end = range == null ? 1 : start + range.getLength();
396
		marker.setAttributes(
411
		marker.setAttributes(
(-)src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java (+39 lines)
Lines 37-42 Link Here
37
public static Test suite() {
37
public static Test suite() {
38
    return buildTestSuite(PackageInfoTest.class);
38
    return buildTestSuite(PackageInfoTest.class);
39
}
39
}
40
41
//test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=258145 : JME on duplicate package-info
42
public void test258145() throws JavaModelException {
43
    IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$
44
    env.addExternalJars(projectPath, Util.getJavaClassLibs());
45
    fullBuild(projectPath);
46
47
    // remove old package fragment root so that names don't collide
48
    env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$
49
50
    IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$
51
    env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
52
    
53
    IPath otherRoot = env.addPackageFragmentRoot(projectPath, "test"); //$NON-NLS-1$
54
    env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
55
56
    env.addPackage(root, "my.foo");
57
    env.addFile(root, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$
58
    		"/**\n" +
59
            "* A demo package for foo.\n" +
60
            "*/\n" +
61
            "package my.foo;\n"
62
        );
63
    
64
    fullBuild(projectPath);
65
    
66
    env.addPackage(otherRoot, "my.foo");
67
    
68
    
69
    IPath otherPackageInfoPath = env.addFile(otherRoot, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$
70
            "/**\n" +
71
            "* A demo package for foo.\n" +
72
            "*/\n" +
73
            "package my.foo;\n"
74
            );
75
76
    incrementalBuild(projectPath);
77
	expectingOnlySpecificProblemFor(otherPackageInfoPath, new Problem("my/foo/package-info.java", "The type package-info is already defined", otherPackageInfoPath, 0, 0, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$
78
}
40
public void test001() throws JavaModelException {
79
public void test001() throws JavaModelException {
41
    IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$
80
    IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$
42
    env.addExternalJars(projectPath, Util.getJavaClassLibs());
81
    env.addExternalJars(projectPath, Util.getJavaClassLibs());

Return to bug 258145