JDK-4699983 : error in sun.rmi.runtime.Log.LoggerLog.getPrintStream
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.rmi
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2002-06-10
  • Updated: 2002-06-11
  • Resolved: 2002-06-11
Related Reports
Duplicate :  
Description
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

Comments
EVALUATION From just inspection, it appears to me that LoggerPrintStream could and should really just be a static member class-- if that's indeed true, then just making it a static member class would be our preferred solution (I think its ever having an enclosing instance is just extraneous). Otherwise, changing the access of LoggerPrintStream to package access is fine with us. ###@###.### 2002-06-10 As you say, so shall it be done. I shall close this as a dup of the underlying compiler bug as it will be fixed when I put back that change. ###@###.### 2002-06-10
10-06-2002