JDK-4338863 : Component.list(PrintStream out, int indent) works incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 2000-05-17
  • Updated: 2001-12-18
  • Resolved: 2001-12-18
Related Reports
Duplicate :  
Description

Name: dsR10051			Date: 05/17/2000


The methods
public void list(PrintStream out, int indent) and public void list(PrintWriter out, int indent)
works incorrectly. It adds double indent before a string representation of this component.

Here is a minimized test:
import java.awt.*;
import java.io.*;

public class ComponentTest3 {

    public static void main (String[] args) {
        CharArrayWriter chaw = new CharArrayWriter();
        PrintWriter pw = new PrintWriter(chaw);
        Component c = new Canvas();
        int indent = 5;
        String str_indent = "     ";
        c.list(pw, indent);
        pw.flush();
        String result = chaw.toString();
        System.out.println(result);
        pw.close();
        if (!result.startsWith(str_indent + c.toString())) {
            System.out.println(str_indent + c.toString() + ": EXPECTED");
            System.out.println("FAILED");
        } else {
            System.out.println("OKAY");
        }
    }
}

Output:
%java -version       
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-B)
Java HotSpot(TM) Client VM (build 1.3.0-B, interpreted mode)
%java ComponentTest3 
          java.awt.Canvas[canvas0,0,0,0x0,invalid]

     java.awt.Canvas[canvas0,0,0,0x0,invalid]: EXPECTED
FAILED

======================================================================

Comments
WORK AROUND Only workaround is subclassing.
11-06-2004

SUGGESTED FIX ------- Component.java ------- *** /tmp/d0FaGZh Mon Nov 26 13:13:00 2001 --- Component.java Mon Nov 26 13:12:49 2001 *************** *** 6382,6388 **** */ public void list(PrintStream out, int indent) { for (int i = 0 ; i < indent ; i++) { ! out.print(" "); } out.println(this); } --- 6382,6388 ---- */ public void list(PrintStream out, int indent) { for (int i = 0 ; i < indent ; i++) { ! out.print(" "); } out.println(this); } ###@###.### 2001-11-26
26-11-2001

EVALUATION Easy to fix, though behavior has been broken since 1.0. I am not sure if anyone is counting on the broken behavior. I doubt it, since the list() method is generally used for logging and debugging purposes only. ###@###.### 2001-11-26
26-11-2001