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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 148-153 Link Here
148
		buildMethods();
149
		buildMethods();
149
150
150
		SourceTypeBinding sourceType = this.referenceContext.binding;
151
		SourceTypeBinding sourceType = this.referenceContext.binding;
152
		if (!sourceType.isPrivate() && sourceType.superclass instanceof SourceTypeBinding && sourceType.superclass.isPrivate())
153
			((SourceTypeBinding) sourceType.superclass).tagIndirectlyAccessibleMembers();
154
		
151
		if (sourceType.isMemberType() && !sourceType.isLocalType())
155
		if (sourceType.isMemberType() && !sourceType.isLocalType())
152
			 ((MemberTypeBinding) sourceType).checkSyntheticArgsAndFields();
156
			 ((MemberTypeBinding) sourceType).checkSyntheticArgsAndFields();
153
157
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java (-2 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 31-37 Link Here
31
	final int AccUnresolved = ASTNode.Bit26;
32
	final int AccUnresolved = ASTNode.Bit26;
32
	final int AccBlankFinal = ASTNode.Bit27; // for blank final variables
33
	final int AccBlankFinal = ASTNode.Bit27; // for blank final variables
33
	final int AccIsDefaultConstructor = ASTNode.Bit27; // for default constructor
34
	final int AccIsDefaultConstructor = ASTNode.Bit27; // for default constructor
34
	final int AccLocallyUsed = ASTNode.Bit28; // used to diagnose unused private/local members
35
	final int AccLocallyUsed = ASTNode.Bit28; // used to diagnose unused (a) private/local members or (b) members of private classes
36
											  // generally set when actual usage has been detected 
37
											  // or, (b) when member of a private class is exposed via a non-private subclass
38
											  //     see https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
35
	final int AccVisibilityMASK = ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate;
39
	final int AccVisibilityMASK = ClassFileConstants.AccPublic | ClassFileConstants.AccProtected | ClassFileConstants.AccPrivate;
36
40
37
	final int AccOverriding = ASTNode.Bit29; // record fact a method overrides another one
41
	final int AccOverriding = ASTNode.Bit29; // record fact a method overrides another one
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (+16 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 1680-1683 Link Here
1680
public FieldBinding[] unResolvedFields() {
1681
public FieldBinding[] unResolvedFields() {
1681
	return this.fields;
1682
	return this.fields;
1682
}
1683
}
1684
1685
public void tagIndirectlyAccessibleMembers() {
1686
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
1687
	for (int i = 0; i < this.fields.length; i++) {
1688
		if (!this.fields[i].isPrivate())
1689
			this.fields[i].modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
1690
	}
1691
	for (int i = 0; i < this.memberTypes.length; i++) {
1692
		if (!this.memberTypes[i].isPrivate())
1693
			this.memberTypes[i].modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
1694
	}
1695
	if (this.superclass.isPrivate()) 
1696
		if (this.superclass instanceof SourceTypeBinding)  // should always be true because private super type can only be accessed in same CU
1697
			((SourceTypeBinding) this.superclass).tagIndirectlyAccessibleMembers();
1698
}
1683
}
1699
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java (+147 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 5154-5159 Link Here
5154
		"----------\n");
5155
		"----------\n");
5155
}
5156
}
5156
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5157
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5158
// check independence of textual order
5159
public void test099a() {
5160
	this.runNegativeTest(
5161
		new String[] {
5162
			"X.java",
5163
			"public class X {\n" +
5164
			"   public class C extends B {\n" +
5165
		    "		public void foo(int a) {\n" +
5166
			"			System.out.println(\"Hello\");\n" +    
5167
			"		}\n" +
5168
		    "		public void foo(double a) {\n" +
5169
			"			System.out.println(\"Hello\");\n" +    
5170
			"		}\n" +
5171
			"		public void foo(boolean a) {\n" +
5172
			"			System.out.println(\"Hello\");\n" +    
5173
			"		}\n" +
5174
			"		public void foo(byte a) {\n" +
5175
			"			System.out.println(\"Hello\");\n" +     
5176
			"		}\n" +
5177
		    "   }\n" +
5178
			"   private class B extends A {\n" +
5179
			"		public void foo(int a) {\n" +
5180
			"   		System.out.println(\"Hello\");\n" +    
5181
			"   	}\n" +
5182
			"		public void foo(float a) {\n" +
5183
			"   		System.out.println(\"Hello\");\n" +    
5184
			"   	}\n" +
5185
			"   	public void foo(double a) {\n" +
5186
			"   		System.out.println(\"Hello\");\n" +    
5187
			"   	}\n" +
5188
			"   	public void foo(char a) {\n" +
5189
			"   		System.out.println(\"Hello\");\n" +    
5190
			"   	}\n" +
5191
			"   }\n" +
5192
			"   private class A {\n" +
5193
			"    	public void foo(int a) {\n" +
5194
			"   		System.out.println(\"Hello\");\n" +    
5195
			"    	}\n" +
5196
			"	    public void foo(float a) {\n" +
5197
			"   		System.out.println(\"Hello\");\n" + 
5198
			"   	}\n" +
5199
			"   	public void foo(boolean a) {\n" +
5200
			"   		System.out.println(\"Hello\");\n" +    
5201
			"   	}\n" +
5202
			"      	public void foo(Integer a) {\n" +
5203
			"   		System.out.println(\"Hello\");\n" +    
5204
			"   	}\n" +
5205
			"   }\n" + 
5206
			"}\n"
5207
		},
5208
		"----------\n" + 
5209
		"1. WARNING in X.java (at line 2)\n" + 
5210
		"	public class C extends B {\n" + 
5211
		"	             ^\n" + 
5212
		"Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + 
5213
		"----------\n" + 
5214
		"2. WARNING in X.java (at line 16)\n" + 
5215
		"	private class B extends A {\n" + 
5216
		"	              ^\n" + 
5217
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5218
		"----------\n" + 
5219
		"3. WARNING in X.java (at line 23)\n" + 
5220
		"	public void foo(double a) {\n" + 
5221
		"	            ^^^^^^^^^^^^^\n" + 
5222
		"The method foo(double) from the type X.B is never used locally\n" + 
5223
		"----------\n" + 
5224
		"4. WARNING in X.java (at line 31)\n" + 
5225
		"	public void foo(int a) {\n" + 
5226
		"	            ^^^^^^^^^^\n" + 
5227
		"The method foo(int) from the type X.A is never used locally\n" + 
5228
		"----------\n" + 
5229
		"5. WARNING in X.java (at line 34)\n" + 
5230
		"	public void foo(float a) {\n" + 
5231
		"	            ^^^^^^^^^^^^\n" + 
5232
		"The method foo(float) from the type X.A is never used locally\n" + 
5233
		"----------\n" + 
5234
		"6. WARNING in X.java (at line 37)\n" + 
5235
		"	public void foo(boolean a) {\n" + 
5236
		"	            ^^^^^^^^^^^^^^\n" + 
5237
		"The method foo(boolean) from the type X.A is never used locally\n" + 
5238
		"----------\n");
5239
}
5240
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5241
// check usage via super-call
5242
public void test099b() {
5243
	this.runNegativeTest(
5244
		new String[] {
5245
			"X.java",
5246
			"public class X {\n" +
5247
			"    private class A {\n" +
5248
			"    	public void foo(int a) {\n" +
5249
			"   		System.out.println(\"Hello\");\n" +    
5250
			"    	}\n" +
5251
			"	    public void foo(float a) {\n" +
5252
			"   		System.out.println(\"Hello\");\n" + 
5253
			"   	}\n" +
5254
			"   	public void foo(boolean a) {\n" +
5255
			"   		System.out.println(\"Hello\");\n" +    
5256
			"   	}\n" +
5257
			"      	public void foo(Integer a) {\n" +
5258
			"   		System.out.println(\"Hello\");\n" +    
5259
			"   	}\n" +
5260
			"   }\n" + 
5261
			"   private class B extends A {\n" +
5262
			"		public void foo(int a) {\n" +
5263
			"   		super.foo(a);\n" +    
5264
			"   	}\n" +
5265
			"		public void foo(float a) {\n" +
5266
			"   		super.foo(a);\n" +    
5267
			"   	}\n" +
5268
			"   	public void foo(double a) {\n" +
5269
			"   		System.out.println(\"Hello\");\n" +    
5270
			"   	}\n" +
5271
			"   	public void foo(char a) {\n" +
5272
			"   		System.out.println(\"Hello\");\n" +    
5273
			"   	}\n" +
5274
			"   }\n" +
5275
			"   public class C extends B {\n" +
5276
		    "		public void foo(int a) {\n" +
5277
			"			System.out.println(\"Hello\");\n" +    
5278
			"		}\n" +
5279
		    "		public void foo(double a) {\n" +
5280
			"			super.foo(a);\n" +    
5281
			"		}\n" +
5282
			"		public void foo(boolean a) {\n" +
5283
			"			super.foo(a);\n" +    
5284
			"		}\n" +
5285
			"		public void foo(byte a) {\n" +
5286
			"			System.out.println(\"Hello\");\n" +     
5287
			"		}\n" +
5288
		    "   }\n" +
5289
			"}\n"
5290
		},
5291
		"----------\n" + 
5292
		"1. WARNING in X.java (at line 16)\n" + 
5293
		"	private class B extends A {\n" + 
5294
		"	              ^\n" + 
5295
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5296
		"----------\n" + 
5297
		"2. WARNING in X.java (at line 30)\n" + 
5298
		"	public class C extends B {\n" + 
5299
		"	             ^\n" + 
5300
		"Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + 
5301
		"----------\n");
5302
}
5303
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5157
public void test100() {
5304
public void test100() {
5158
	this.runNegativeTest(
5305
	this.runNegativeTest(
5159
		new String[] {
5306
		new String[] {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (-2 / +77 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for
11
 *     						bug 185682 - Increment/decrement operators mark local variables as read
12
 *     						bug 328281 - visibility leaks not detected when analyzing unused field in private class
11
 *******************************************************************************/
13
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.compiler.regression;
14
package org.eclipse.jdt.core.tests.compiler.regression;
13
15
Lines 36-42 Link Here
36
  	// Only the highest compliance level is run; add the VM argument
38
  	// Only the highest compliance level is run; add the VM argument
37
  	// -Dcompliance=1.4 (for example) to lower it if needed
39
  	// -Dcompliance=1.4 (for example) to lower it if needed
38
  	static {
40
  	static {
39
//    	TESTS_NAMES = new String[] { "test0055" };
41
//    	TESTS_NAMES = new String[] { "test0052" };
40
//		TESTS_NUMBERS = new int[] { 56 };
42
//		TESTS_NUMBERS = new int[] { 56 };
41
//  	TESTS_RANGE = new int[] { 1, -1 };
43
//  	TESTS_RANGE = new int[] { 1, -1 };
42
  	}
44
  	}
Lines 2125-2130 Link Here
2125
			true/*shouldFlushOutputDirectory*/,
2127
			true/*shouldFlushOutputDirectory*/,
2126
			customOptions);
2128
			customOptions);
2127
}
2129
}
2130
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
2131
public void test0052() {
2132
	Map customOptions = getCompilerOptions();
2133
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
2134
	this.runConformTest(
2135
			new String[] {
2136
					"X.java",
2137
					"class X {\n" +
2138
					"    Y y = new Y();\n" +
2139
					"    private class Y {\n" +
2140
					"        int abc;\n" + 
2141
					"        Y() {\n" + 
2142
					"            abc++;\n" +    // not a relevant usage
2143
					"        }\n" +
2144
					"    }\n" +
2145
					"    class Z extends Y {}\n" + // makes 'abc' externally accessible
2146
					"}"
2147
			},
2148
			"",
2149
			null/*classLibraries*/,
2150
			true/*shouldFlushOutputDirectory*/,
2151
			null/*vmArguments*/,
2152
			customOptions,
2153
			null/*requestor*/);
2154
}
2155
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
2156
// multi-level inheritance
2157
public void test0052a() {
2158
	Map customOptions = getCompilerOptions();
2159
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
2160
	customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
2161
	this.runConformTest(
2162
			new String[] {
2163
					"Outer.java",
2164
					"class Outer {\n" + 
2165
					"    private class Inner1 {\n" + 
2166
					"        int foo;\n" +
2167
					"    }\n" + 
2168
					"    private class Inner2 extends Inner1 { }\n" + 
2169
					"    class Inner3 extends Inner2 { }\n" +  // foo is exposed here
2170
					"}\n"
2171
			},
2172
			"",
2173
			null/*classLibraries*/,
2174
			true/*shouldFlushOutputDirectory*/,
2175
			null/*vmArguments*/,
2176
			customOptions,
2177
			null/*requestor*/);
2178
}
2179
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
2180
// member type of private
2181
public void test0052b() {
2182
	Map customOptions = getCompilerOptions();
2183
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
2184
	customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
2185
	this.runConformTest(
2186
			new String[] {
2187
					"Outer.java",
2188
					"class Outer {\n" + 
2189
					"    private class Inner1 {\n" + 
2190
					"        class Foo{}\n" +
2191
					"    }\n" + 
2192
					"    private class Inner2 extends Inner1 { }\n" + 
2193
					"    class Inner3 extends Inner2 { }\n" +  // Foo is exposed here
2194
					"}\n"
2195
			},
2196
			"",
2197
			null/*classLibraries*/,
2198
			true/*shouldFlushOutputDirectory*/,
2199
			null/*vmArguments*/,
2200
			customOptions,
2201
			null/*requestor*/);
2202
}
2128
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519
2203
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519
2129
public void test0053() throws Exception {
2204
public void test0053() throws Exception {
2130
	Map customOptions = getCompilerOptions();
2205
	Map customOptions = getCompilerOptions();

Return to bug 328281