### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.181 diff -u -r1.181 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 20 Oct 2010 05:46:47 -0000 1.181 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 23 Oct 2010 00:32:54 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -903,6 +904,8 @@ } else { // only want to reach here when no errors are reported sourceType.superclass = superclass; + if (superclass.isPrivate() && !sourceType.isPrivate()) + superclass.tagBits |= TagBits.IsPrivateWithNonPrivateSub; return true; } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java,v retrieving revision 1.139 diff -u -r1.139 ReferenceBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 3 Feb 2010 06:34:21 -0000 1.139 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 23 Oct 2010 00:32:56 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -1108,7 +1109,7 @@ if (isLocalType()) return true; // catch all local types ReferenceBinding type = this; while (type != null) { - if ((type.modifiers & ClassFileConstants.AccPrivate) != 0) + if ((type.modifiers & ClassFileConstants.AccPrivate) != 0 && (type.tagBits & TagBits.IsPrivateWithNonPrivateSub) == 0) return true; type = type.enclosingType(); } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java,v retrieving revision 1.44 diff -u -r1.44 TagBits.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 21 Sep 2010 14:02:58 -0000 1.44 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 23 Oct 2010 00:32:56 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 328281 - visibility leaks not detected when analyzing unused field in private class *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; @@ -122,4 +123,7 @@ // set when type contains non-private constructor(s) long HasNonPrivateConstructor = ASTNode.Bit53L; + + // set when a private class has a non-private subclass + long IsPrivateWithNonPrivateSub = ASTNode.Bit54L; } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java,v retrieving revision 1.26 diff -u -r1.26 ProgrammingProblemsTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 22 Oct 2010 22:42:32 -0000 1.26 +++ src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java 23 Oct 2010 00:33:03 -0000 @@ -7,7 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + * Stephan Herrmann - Contributions for + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 328281 - visibility leaks not detected when analyzing unused field in private class *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -2120,5 +2122,30 @@ true/*shouldFlushOutputDirectory*/, customOptions); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281 +public void test0052() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Y y = new Y();\n" + + " private class Y {\n" + + " int abc;\n" + + " Y() {\n" + + " abc++;\n" + // not a relevant usage + " }\n" + + " }\n" + + " class Z extends Y {}\n" + // makes 'abc' externally accessible + "}" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null/*vmArguments*/, + customOptions, + null/*requestor*/); +} } \ No newline at end of file