Given the following illegal program, the compiler enters what appears to be an
infinite loop:
public class Bug {
private void foo() {
}
private Thread bar
= new Thread() {
public void run() {
for (;;) {
Bug.this.foo();
}
}
};
}
If the for loop is removed but the invocation of foo() left intact, then the
compiler terminates. Both behaviors are wrong since foo() is private and
access to it should not be allowed. The 1.1 compiler gets this right, but
seems to have another problem:
% /usr/local/java/jdk1.1/solaris/bin/javac Bug.java
ERROR: sun.tools.java.CompilerError: stack under flow: 8: putfield java.lang.Thread bar = -1
-- listing --
$3:
2: aload 0
2: invokespecial java.lang.Object()
8: aload 0
8: new local class Bug. 1
8: dup
0: aload 0
8: invokespecial Bug. 1(Bug,Bug)
8: putfield java.lang.Thread bar
2: return
Bug.java:11: Access across scopes to the private member void foo() in class Bug is not implemented. The reference will succeed if the member is given package scope.
Bug.this.foo();
^
1 error
%
infinite loop:
public class Bug {
private void foo() {
}
private Thread bar
= new Thread() {
public void run() {
for (;;) {
Bug.this.foo();
}
}
};
}
If the for loop is removed but the invocation of foo() left intact, then the
compiler terminates. Both behaviors are wrong since foo() is private and
access to it should not be allowed. The 1.1 compiler gets this right, but
seems to have another problem:
% /usr/local/java/jdk1.1/solaris/bin/javac Bug.java
ERROR: sun.tools.java.CompilerError: stack under flow: 8: putfield java.lang.Thread bar = -1
-- listing --
$3:
2: aload 0
2: invokespecial java.lang.Object()
8: aload 0
8: new local class Bug. 1
8: dup
0: aload 0
8: invokespecial Bug. 1(Bug,Bug)
8: putfield java.lang.Thread bar
2: return
Bug.java:11: Access across scopes to the private member void foo() in class Bug is not implemented. The reference will succeed if the member is given package scope.
Bug.this.foo();
^
1 error
%
- duplicates
-
JDK-4051281 Problem compiling when inner class references a private method
-
- Closed
-