Skip to content

Commit babd4d4

Browse files
committed
Fixed for Bug4986
1 parent 1dc8186 commit babd4d4

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,8 +3357,20 @@ public void importProblem(ImportReference importRef, Binding expectedImport) {
33573357
case ProblemReasons.NotVisible :
33583358
case ProblemReasons.NotAccessible :
33593359
id = (expectedImport.problemId() == ProblemReasons.NotVisible) ? IProblem.NotVisibleField : IProblem.NotAccessibleField;
3360-
readableArguments = new String[] {CharOperation.toString(importRef.tokens), new String(field.declaringClass.readableName())};
3361-
shortArguments = new String[] {CharOperation.toString(importRef.tokens), new String(field.declaringClass.shortReadableName())};
3360+
char[] readableName = CharOperation.concat(
3361+
field.declaringClass.readableName(),
3362+
field.name,
3363+
'.');
3364+
char[] shortReadableName = CharOperation.concat(
3365+
field.declaringClass.shortReadableName(),
3366+
field.name,
3367+
'.');
3368+
readableArguments = new String[] {
3369+
new String(readableName)
3370+
};
3371+
shortArguments = new String[] {
3372+
new String(shortReadableName)
3373+
};
33623374
break;
33633375
case ProblemReasons.Ambiguous :
33643376
id = IProblem.AmbiguousField;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
68 = Too many array dimensions. Maximum is 255
105105
69 = The code of constructor {0}({1}) is exceeding the 65535 bytes limit
106106
70 = {0} cannot be resolved or is not a field
107-
71 = The field {1}.{0} is not visible
107+
71 = The field {0} is not visible
108108
72 = The field {0} is ambiguous
109109
73 = The field {0}.{1} is deprecated
110110
74 = Cannot make a static reference to the non-static field {0}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,4 +3559,30 @@ public class Sub extends Super {}
35593559
runner.expectedOutputString = "1";
35603560
runner.runConformTest();
35613561
}
3562+
3563+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4986
3564+
// Test that error message for inaccessible static import field is correctly formatted
3565+
public void testBug4986() {
3566+
this.runNegativeTest(
3567+
new String[] {
3568+
"p/C.java",
3569+
"package p;\n" +
3570+
"import static p.C.f;\n" +
3571+
"public class C {\n" +
3572+
" private static int f;\n" +
3573+
"}\n"
3574+
},
3575+
"----------\n" +
3576+
"1. ERROR in p\\C.java (at line 2)\n" +
3577+
"\timport static p.C.f;\n" +
3578+
"\t ^^^^^\n" +
3579+
"The field C.f is not visible\n" +
3580+
"----------\n" +
3581+
"2. WARNING in p\\C.java (at line 4)\n" +
3582+
"\tprivate static int f;\n" +
3583+
"\t ^\n" +
3584+
"The value of the field C.f is not used\n" +
3585+
"----------\n"
3586+
);
3587+
}
35623588
}

0 commit comments

Comments
 (0)