Skip to content

Commit

Permalink
Allow references to static locks in enclosing classes
Browse files Browse the repository at this point in the history
The only case we want to disallow is static member classes accessing locks in
enclosing classes.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184911398
  • Loading branch information
cushon authored and eaftan committed Feb 9, 2018
1 parent 0ad7c3f commit fc1cd4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -162,6 +162,14 @@ private <T extends Symbol> T getMember(
return sym;
}
}
if (classSymbol.owner != null
&& classSymbol != classSymbol.owner
&& classSymbol.owner instanceof Symbol.ClassSymbol) {
T sym = getMember(type, kind, classSymbol.owner, name);
if (sym != null && sym.isStatic()) {
return sym;
}
}
return null;
}

Expand Down
Expand Up @@ -1592,7 +1592,7 @@ public void multipleLocks() throws Exception {
// Ensure sure outer instance handling doesn't accidentally include enclosing classes of
// static member classes.
@Test
public void testInnerClass_staticOuterClassLock() throws Exception {
public void testStaticMemberClass_enclosingInstanceLock() throws Exception {
compilationHelper
.addSourceLines(
"threadsafety/Test.java",
Expand All @@ -1612,4 +1612,27 @@ public void testInnerClass_staticOuterClassLock() throws Exception {
"}")
.doTest();
}

// Ensure sure outer instance handling doesn't accidentally include enclosing classes of
// static member classes.
@Test
public void testStaticMemberClass_staticOuterClassLock() throws Exception {
compilationHelper
.addSourceLines(
"threadsafety/Test.java",
"package threadsafety;",
"import javax.annotation.concurrent.GuardedBy;",
"public class Test {",
" static final Object mu = new Object();",
" private static final class Baz {",
" @GuardedBy(\"mu\") int x;",
" }",
" public void m(Baz b) {",
" synchronized (mu) {",
" b.x++;",
" }",
" }",
"}")
.doTest();
}
}

0 comments on commit fc1cd4a

Please sign in to comment.