java/1426: Compiler fails to catch constructor problem

green@cygnus.com green@cygnus.com
Wed Dec 20 12:26:00 GMT 2000


>Number:         1426
>Category:       java
>Synopsis:       Compiler fails to catch constructor problem
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    apbianco
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 20 12:19:43 PST 2000
>Closed-Date:    Mon Nov 01 01:59:54 PST 1999
>Last-Modified:  Mon Nov  1 02:00:00 PST 1999
>Originator:     Anthony Green
>Release:        2.96 (trunk)
>Organization:
>Environment:

>Description:
The compiler fails to catch the use of `this' in a 
constructor before calling the superclass constructor.
>How-To-Repeat:
The following patch corrects invalid 
code in java/io/OutputStreamWriter.java.
Revert this patch.  The compiler should issue an error.
Compiling it with javac produces:

./java/io/OutputStreamWriter.java:35: Can't reference this before the superclass constructor has been called.
    super((this.out = (out instanceof BufferedOutputStream
 


Index: java/io/OutputStreamWriter.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/OutputStreamWriter.java,v
retrieving revision 1.2
diff -u -r1.2 OutputStreamWriter.java
--- OutputStreamWriter.java	1999/04/16 18:35:01	1.2
+++ OutputStreamWriter.java	1999/09/21 19:44:32
@@ -32,9 +32,11 @@
 
   private OutputStreamWriter(OutputStream out, UnicodeToBytes encoder)
   {
-    super((this.out = (out instanceof BufferedOutputStream
-		       ? (BufferedOutputStream) out
-		       : new BufferedOutputStream(out, 250))));
+    BufferedOutputStream buf = (out instanceof BufferedOutputStream
+				? (BufferedOutputStream) out
+				: new BufferedOutputStream(out, 250));
+    super (buf);
+    this.out = buf;
     this.converter = encoder;
   } 
>Fix:

>Release-Note:

>Audit-Trail:

Formerly PR gcj/48


From: Tom Tromey <tromey@cygnus.com>
To: Java Gnats Server <java-gnats@sourceware.cygnus.com> 
Cc:  
Subject: gcj/48
Date: 21 Sep 1999 15:53:52 -0600

 Note that PR #50 refers to the java.io side of this problem.
 The patch that was checked in was reverted due to incorrectness :-(.
 
 Tom
State-Changed-From-To: open->feedback
State-Changed-By: apbianco
State-Changed-When: Fri Oct 29 08:51:27 1999
State-Changed-Why:
    Patch send to the mailing list.

From: apbianco@cygnus.com
To: apbianco@cygnus.com, green@cygnus.com, java-gnats@sourceware.cygnus.com
Cc:  
Subject: Re: gcj/48
Date: 29 Oct 1999 15:51:27 -0000

 Synopsis: Compiler fails to catch constructor problem
 
 State-Changed-From-To: open->feedback
 State-Changed-By: apbianco
 State-Changed-When: Fri Oct 29 08:51:27 1999
 State-Changed-Why:
     Patch send to the mailing list.
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&database=java&pr=48

From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: green@cygnus.com
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/48: Compiler fails to catch constructor problem
Date: Fri, 29 Oct 1999 08:51:34 -0700 (PDT)

 green@cygnus.com writes:
 
 > The compiler fails to catch the use of `this' in a 
 > constructor before calling the superclass constructor.
 
 I have a patch for that, see below. With that patch, I get several
 failures compiling libjava:
 
 --
 java/io/InputStreamReader.java:47: Can't reference `this' before the superclass constructor has been called.
     super((this.in = (in instanceof BufferedInputStream
            ^
 1 error
 
 java/io/OutputStreamWriter.java:35: Can't reference `this' before the superclass constructor has been called.
     super((this.out = (out instanceof BufferedOutputStream
            ^
 1 error
 
 java/io/PrintStream.java:241: Can't reference `this' before the superclass constructor has been called.
     super ((this.out = (out instanceof BufferedOutputStream
             ^
 1 error
 --
 
 If someone can confirm these errors, I'll update PR #50 with the
 mention of `InputStreamReader'.
 
 ./A
 
 Index: parse.y
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
 retrieving revision 1.114
 diff -u -p -r1.114 parse.y
 --- parse.y	1999/10/22 06:06:47	1.114
 +++ parse.y	1999/10/29 15:29:12
 @@ -6716,6 +6716,12 @@ resolve_qualified_expression_name (wfl, 
  		(wfl, "Keyword `this' used outside allowed context");
  	      return 1;
  	    }
 +	  if (ctxp->explicit_constructor_p)
 +	    {
 +	      parse_error_context (wfl, "Can't reference `this' before the "
 +				   "superclass constructor has been called");
 +	      return 1;
 +	    }
  	  /* We have to generate code for intermediate acess */
  	  *where_found = decl = current_this;
  	  *type_found = type = QUAL_DECL_TYPE (decl);
 @@ -8723,7 +8729,7 @@ complete_function_arguments (node)
    int flag = 0;
    tree cn;
  
 -  ctxp->explicit_constructor_p += (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
 +  ctxp->explicit_constructor_p += (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
    for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
      {
        tree wfl = TREE_VALUE (cn), parm, temp;
 @@ -8743,7 +8749,7 @@ complete_function_arguments (node)
  
        TREE_VALUE (cn) = parm;
      }
 -  ctxp->explicit_constructor_p -= (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
 +  ctxp->explicit_constructor_p -= (CALL_EXPLICIT_CONSTRUCTOR_P (node) ? 1 : 0);
    return flag;
  }
  
State-Changed-From-To: feedback->closed
State-Changed-By: apbianco
State-Changed-When: Mon Nov  1 01:59:54 1999
State-Changed-Why:
    I checked in this patch:
      http://egcs.cygnus.com/ml/gcc-patches/1999-11/msg00004.html

From: apbianco@cygnus.com
To: apbianco@cygnus.com, green@cygnus.com, java-gnats@sourceware.cygnus.com
Cc:  
Subject: Re: gcj/48
Date: 1 Nov 1999 09:59:54 -0000

 Synopsis: Compiler fails to catch constructor problem
 
 State-Changed-From-To: feedback->closed
 State-Changed-By: apbianco
 State-Changed-When: Mon Nov  1 01:59:54 1999
 State-Changed-Why:
     I checked in this patch:
       http://egcs.cygnus.com/ml/gcc-patches/1999-11/msg00004.html
 
 http://sourceware.cygnus.com/cgi-bin/gnatsweb.pl?cmd=view&database=java&pr=48
>Unformatted:




More information about the Gcc-prs mailing list