You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Anton Ivanov (JIRA)" <ji...@apache.org> on 2006/12/12 13:24:21 UTC

[jira] Created: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

[luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
--------------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-2638
                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Anton Ivanov
            Priority: Minor


It is said in the specification of the method Throwable.printStackTrace():
"The first line of output contains the result of the toString() method for this object"
But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.

The test to reproduce the problem:

import javax.naming.*;
import java.io.*;

public class NamingExceptionTest {

    public static void main(String[] args) throws Exception {
        NamingException ex = new NamingException("test message");        
        ByteArrayOutputStream bStream = new ByteArrayOutputStream();
        PrintStream stream = new PrintStream(bStream);
        
        String firstString;
        String stackTrace;
 
        System.setErr(stream);
        ex.setRemainingName(new CompositeName("element/parent"));
        ex.setRootCause(new Exception("root cause1"));

        ex.printStackTrace();
        stackTrace = bStream.toString();     
        firstString = ex.toString();
       
        if (stackTrace.startsWith(firstString)) {
            System.out.println("PASSED");
        } else {
            System.out.println("FAILED");
        }
    }
}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2638?page=comments#action_12457697 ] 
            
Vasily Zakharov commented on HARMONY-2638:
------------------------------------------

I wonder why our implementation overrides that method at all.
In RI, as you may see in JavaDoc, NamingException doesn't override printStackTrace() methods.

Also, it looks like the following spec statement is violated:
"This exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The root exception (or root cause) is the same object as the cause returned by the Throwable.getCause() method."

It means that the same field must be used for getRootCause(), setRootCause(), getCause() and initCause() methods, and that is not true for our implementation. The overridden getCause() and initCause() do nothing in fact.

Looks like this class requires essential cleanup.


> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2638?page=all ]

Vasily Zakharov updated HARMONY-2638:
-------------------------------------

    Attachment: HARMONY-2638.patch

Attached patch that resolves the issues listed above.

- Removed printStackTrace() overriding methods, that fixes the primary issue.

- Adjusted getCause() and initCause() methods to fit the specification.

- Removed some extra empty lines at the end.

- Fixed org.apache.harmony.jndi.tests.javax.naming.NamingExceptionTest.testPrintStackTrace() test case. Before the patch if failed on RI, now it passes on both RI and patched Harmony classlib.


> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>            Priority: Minor
>         Attachments: HARMONY-2638.patch
>
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2638?page=all ]

Tim Ellison closed HARMONY-2638.
--------------------------------


Verified by Vasily.


> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>         Assigned To: Tim Ellison
>            Priority: Minor
>         Attachments: HARMONY-2638.patch
>
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2638?page=all ]

Tim Ellison resolved HARMONY-2638.
----------------------------------

    Resolution: Fixed

Thanks Anton / Vasily.

Patch applied to JNDI module at repo revision r488292.

Please check that it was applied as you expected.


> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>         Assigned To: Tim Ellison
>            Priority: Minor
>         Attachments: HARMONY-2638.patch
>
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2638?page=comments#action_12459564 ] 
            
Vasily Zakharov commented on HARMONY-2638:
------------------------------------------

Thanks Tim, the patch is fine.


> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>         Assigned To: Tim Ellison
>            Priority: Minor
>         Attachments: HARMONY-2638.patch
>
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Assigned: (HARMONY-2638) [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2638?page=all ]

Tim Ellison reassigned HARMONY-2638:
------------------------------------

    Assignee: Tim Ellison

> [luni][jndi] javax.naming.NamingException.printStackTrace() output should contain the output of NamingException.toString()
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2638
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2638
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Anton Ivanov
>         Assigned To: Tim Ellison
>            Priority: Minor
>         Attachments: HARMONY-2638.patch
>
>
> It is said in the specification of the method Throwable.printStackTrace():
> "The first line of output contains the result of the toString() method for this object"
> But NamingException.printStackTrace() doesn't follow this instruction. If the method NamingException.setRootCause(Throwable)
> was invoked, NamingException.printStackTrace() will not contain the result of the toString() method for this exception.
> The test to reproduce the problem:
> import javax.naming.*;
> import java.io.*;
> public class NamingExceptionTest {
>     public static void main(String[] args) throws Exception {
>         NamingException ex = new NamingException("test message");        
>         ByteArrayOutputStream bStream = new ByteArrayOutputStream();
>         PrintStream stream = new PrintStream(bStream);
>         
>         String firstString;
>         String stackTrace;
>  
>         System.setErr(stream);
>         ex.setRemainingName(new CompositeName("element/parent"));
>         ex.setRootCause(new Exception("root cause1"));
>         ex.printStackTrace();
>         stackTrace = bStream.toString();     
>         firstString = ex.toString();
>        
>         if (stackTrace.startsWith(firstString)) {
>             System.out.println("PASSED");
>         } else {
>             System.out.println("FAILED");
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira