We are in the process of fixing a compiler bug (4635044) that exposes a bug
in java.text.DictionaryBasedBreakIterator.Builder. The
relevant portions of all participating classes are
1 package sun.rmi.runtime;
2
3 import java.io.PrintStream;
4 import java.util.logging.Logger;
5 import java.io.ByteArrayOutputStream;
6
7 class Log {
8
9 private class LoggerPrintStream extends PrintStream {
10 private LoggerPrintStream(Logger logger)
11 {
12 super(new ByteArrayOutputStream());
13 // ...
14 }
15 }
16
17 static class LoggerLog extends Log {
18 private final Logger logger;
19 private LoggerPrintStream loggerSandwich;
20
21 public synchronized PrintStream getPrintStream() {
22 if (loggerSandwich == null) {
23 loggerSandwich = new LoggerPrintStream(logger);
24 }
25 return loggerSandwich;
26 }
27
28 }
29
30 }
The class creation expression on line 23 is creating an inner class,
which requires an enclosing instance. Since one is not provided by the
programmer, the compiler provides one as per 15.9.2. The only enclosing
class of which LoggerPrintStream is a member is Log. (It is not an inherited
member of LoggerLog because private members are never inherited)
So the compiler is obligated to provide Log.this as the inclosing instance
on line 23. However, since class Log.LoggerLog is declared static inside
class Log, Log.this is unavailable in that context and this the compiler is
obligated to reject this code.
T.java:23: non-static variable this cannot be referenced from a static context
loggerSandwich = new LoggerPrintStream(logger);
^
1 error
The simplest way to correct this problem is to change the protected of
LoggerPrintStream to be protected.
I am doing that in my own copy of the code so that I can proceed with
my compiler bug fixes, but I'd like your blessing (please) on the
correctness of this change. If you approve then please assign this
bug to me (gafter) and
I will put this correction back with my compiler changes. If not then
I will need fixes from you on this code.
###@###.### 2002-06-10