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 (+3 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 903-908 Link Here
903
			} else {
904
			} else {
904
				// only want to reach here when no errors are reported
905
				// only want to reach here when no errors are reported
905
				sourceType.superclass = superclass;
906
				sourceType.superclass = superclass;
907
				if (superclass.isPrivate() && !sourceType.isPrivate())
908
					superclass.tagBits |= TagBits.IsPrivateWithNonPrivateSub;
906
				return true;
909
				return true;
907
			}
910
			}
908
		}
911
		}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java (-1 / +2 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 1108-1114 Link Here
1108
	if (isLocalType()) return true; // catch all local types
1109
	if (isLocalType()) return true; // catch all local types
1109
	ReferenceBinding type = this;
1110
	ReferenceBinding type = this;
1110
	while (type != null) {
1111
	while (type != null) {
1111
		if ((type.modifiers & ClassFileConstants.AccPrivate) != 0)
1112
		if ((type.modifiers & ClassFileConstants.AccPrivate) != 0 && (type.tagBits & TagBits.IsPrivateWithNonPrivateSub) == 0)
1112
			return true;
1113
			return true;
1113
		type = type.enclosingType();
1114
		type = type.enclosingType();
1114
	}
1115
	}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java (+4 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 122-125 Link Here
122
123
123
	// set when type contains non-private constructor(s)
124
	// set when type contains non-private constructor(s)
124
	long HasNonPrivateConstructor = ASTNode.Bit53L;
125
	long HasNonPrivateConstructor = ASTNode.Bit53L;
126
127
	// set when a private class has a non-private subclass
128
	long IsPrivateWithNonPrivateSub = ASTNode.Bit54L;
125
}
129
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (-1 / +28 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 2120-2124 Link Here
2120
			true/*shouldFlushOutputDirectory*/,
2122
			true/*shouldFlushOutputDirectory*/,
2121
			customOptions);
2123
			customOptions);
2122
}
2124
}
2125
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281
2126
public void test0052() {
2127
	Map customOptions = getCompilerOptions();
2128
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
2129
	this.runConformTest(
2130
			new String[] {
2131
					"X.java",
2132
					"class X {\n" +
2133
					"    Y y = new Y();\n" +
2134
					"    private class Y {\n" +
2135
					"        int abc;\n" + 
2136
					"        Y() {\n" + 
2137
					"            abc++;\n" +    // not a relevant usage
2138
					"        }\n" +
2139
					"    }\n" +
2140
					"    class Z extends Y {}\n" + // makes 'abc' externally accessible
2141
					"}"
2142
			},
2143
			"",
2144
			null/*classLibraries*/,
2145
			true/*shouldFlushOutputDirectory*/,
2146
			null/*vmArguments*/,
2147
			customOptions,
2148
			null/*requestor*/);
2149
}
2123
2150
2124
}
2151
}

Return to bug 328281