JDK-4185460 : Container list the indentation is 2x the indent param value
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.6,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5,solaris_2.6
  • CPU: sparc
  • Submitted: 1998-10-29
  • Updated: 2002-06-17
  • Resolved: 2002-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 hopperFixed
Related Reports
Duplicate :  
Relates :  
Description
In Container list method the first line of output is indented 2 times the 
value of the indent parameter. This is an unexpected result. The 1st line
of output should be printed with indent number of spaces.

Sample output: 
Indent set at: 10
Indent return: 20
                    java.awt.Frame[frame3,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,resizable,title=]
                      java.awt.Button[button15,0,0,0x0,invalid,label=North]
                      java.awt.Button[button16,0,0,0x0,invalid,label=South]
                      java.awt.Button[button17,0,0,0x0,invalid,label=East]
                      java.awt.Button[button18,0,0,0x0,invalid,label=West]
                      java.awt.Button[button19,0,0,0x0,invalid,label=Center]


/*
 * @(#)listTest.java
 * @author Mike Colburn
 * @version 1.0
 *
 * java.awt Container list method tests
 */

import java.awt.*;
import java.io.*;
import java.util.Vector;

/**
 * Method: awt.Container.list
 * <p>Syntax: public void list(PrintStream out, int indent)
 *	      public void list(PrintWriter outwriter, int indent)
 * <p>Param: out 	a print stream
 * <p>Param: outwriter	a print writer
 * <p>Param: indent	the number of spaces to indent
 * <p>Pupose: Prints a listing of this container, starting at the specified 
 *    indention, to the specified output {stream, writer}. 
 * <p>Test: These tests check if the list method works correctly. 
 */
 
public class listTest {        
  
  public static void main(String[] args) {
    
    boolean bReturn = false; 
    int iCompCount = 0;
    int iNotEqual = 0;
    int iIndentWrong = 0;
    System.out.println("Test: Check indentation");
    Vector v = new Vector(); 
    String sLine; 
    String sReturn;      	   
    String sExpTrim;
    Button b1, b2, b3, b4, b5;
    
    try {    
      Frame f = new Frame();                          
             
      f.add(b1 = new Button("North"), BorderLayout.NORTH, 0);       
      f.add(b2 = new Button("South"), BorderLayout.SOUTH, 1);
      f.add(b3 = new Button("East"), BorderLayout.EAST, 2);       
      f.add(b4 = new Button("West"), BorderLayout.WEST, 3);
      f.add(b5 = new Button("Center"), BorderLayout.CENTER, -1);           
    
      String[] sExpected = {f.toString(), b1.toString(), b2.toString(),
    	b3.toString(), b4.toString(), b5.toString()};
    	
      iCompCount = f.getComponentCount();
      System.out.println("Component count: " + iCompCount);  
    
      for (int j = 0; j <= 10; j++) {
      
      	PipedInputStream pin = new PipedInputStream();
      	PrintStream output = new PrintStream(new PipedOutputStream(pin), true);     
      	BufferedReader input = new BufferedReader(new InputStreamReader(pin));
                
      	f.list(output, j);
    
      	output.flush();
      	output.close();
   
      	while ((sLine = input.readLine()) != null) {
    	   v.addElement(sLine); 
      	}             	
      
      	for (int i = 0; i < v.size(); i++) {
      	   sReturn = (String)v.elementAt(i);      	   
      	   sExpTrim = sExpected[i].trim();      	     	   
     	
     	   if ( !(sExpTrim.equals(sReturn.trim())) ) {
    	      ++iNotEqual;    	   
    	   }
    	    	
    	   int iSpace = sReturn.lastIndexOf(' ') + 1;	    	   
    	
    	   if ( i == 0 ) {    	   
    	      System.out.println("Indent set at: " + j);
    	      System.out.println("Indent return: " + iSpace);
    	      if (iSpace != j) {
    	      	++iIndentWrong;
    	      }
    	   } else {
    	      if ( iSpace != (j+2) ) {
    	      	++iIndentWrong;
    	      }
    	   }
    	   System.out.println(sReturn);
      	}  
      	v.removeAllElements();
      	v.trimToSize();                
      
      } // end for
      
      if ( iNotEqual == 0 && iIndentWrong == 0 ) { 
    	bReturn = true;
      } else {
      	bReturn = false;      	
      }                     
    
    } catch(IOException e) {
    	bReturn = false;
   	System.out.println ("Unexpected Exception thrown");      
      	e.printStackTrace();
    }
 
    // check if test passed
    if ( bReturn ) {
      System.out.println("Test for Container.list Passed");      
    } else {
      System.out.println("Test for Container.list Failed");      
    }
  
  }    
  
} // end listTest


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper VERIFIED IN: hopper-beta
24-08-2004

EVALUATION Name: osR10079 Date: 07/04/2001 The problem in Component.list(PrintStream, int) public void list(PrintStream out, int indent) { for (int i = 0 ; i < indent ; i++) { out.print(" "); <-- we print TWO spaces } out.println(this); } ###@###.### 4 Jul 2001 ====================================================================== Name: osR10079 Date: 12/18/2001 After applying suggested fix (see suggested fix section) the testcase still fails, because it assumes that children should be indented by two spaces from their parent. But in documentation we do not specify what indent should be between parent and its children, but our code implements one-space indent. Also i did not find any jdk version (down to 1.1) where this test passes (before 1.1 it doesn't compile). Thus i assume that one-space children indent is the correct behavior. ###@###.### 18 Dec 2001 ====================================================================== Verified on Hopper b14. ###@###.### 2002-06-17
24-08-2004

SUGGESTED FIX Name: osR10079 Date: 12/18/2001 ###@###.### 18 Dec 2001 ------- Component.java ------- *** /tmp/dDAaWrw Tue Dec 18 14:52:50 2001 --- Component.java Tue Dec 18 14:52:24 2001 *************** *** 6379,6385 **** */ public void list(PrintStream out, int indent) { for (int i = 0 ; i < indent ; i++) { ! out.print(" "); } out.println(this); } --- 6379,6385 ---- */ public void list(PrintStream out, int indent) { for (int i = 0 ; i < indent ; i++) { ! out.print(" "); } out.println(this); } ======================================================================
24-08-2004