Extending from the original PR, there are another two tests to consider (which shows why it gets complicated). class OuterClass { void recurse() { class InnerClass { void test() { void localFunction() { void anotherLocalFunction() { recurse(); // Ensure we handle Nth depth. } anotherLocalFunction(); } localFunction(); } } } } class OuterClass { void recurse() { class InnerClass { void test() { void localFunction() { int a = 42; void anotherLocalFunction() { a++; // And correctly handle any // static chains along the way. recurse(); } anotherLocalFunction(); } localFunction(); } } } }