-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
beta2
-
x86
-
windows_2000
-
Verified
Name: asR10013 Date: 06/04/2001
Java Language Specification reads:
public boolean equals(Object obj)
Returns true if the specified object is another StackTraceElement instance representing
the same execution point as this instance. Two stack trace elements a and b are equal if
and only if:
equals(a.getFileName(), b.getFileName()) &&
a.getLineNumber() == b.getLineNumber()) &&
equals(a.getClass(), b.getClass()) &&
equals(a.getMethodName(), b.getMethodName())
where equals is defined as:
static boolean equals(Object a, Object b) {
return a==b || (a != null && a.equals(b));
}
-----------
But the sample code below shows that in some cases
method equals of class StackTraceElement
returns 'false' value instead of expected 'true'.
JDK : JRE1.4.0-b66
JCK : JCK1.4
Platform[s] : Windows 2000 plugin Internet Explorer 5.0
switch/Mode :
JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
Failing Test : api/java_lang/StackTraceElement/index.html#equals
Test source location:
=====================
/net/jdk/export/disk8/local.java/jck1.4/JCK-runtime-14tests/api/java_lang/StackTraceElement/equalsTests.java
jtr file location:
==================
/net/jtgb4u4c.eng/export/sail7/JavaWebServer1.1.3/public_html/QA/merlin/b66/jck14/win32/win95_plugin_ns4.7_linux-19/workDir/api/java_lang/StackTraceElement/index_equals.jtr
How to reproduce:
====================
The following code is adopted from test source code.
Compile it and run as applet in browser.
--------------------------------------------------------------------------
import java.io.PrintWriter;
public class equalsTests extends java.applet.Applet{
static boolean equals(Object a, Object b) {
return a==b || (a != null && a.equals(b));
}
StackTraceElement[] getStackTraceElements(boolean mode) {
try {
if(mode) {throw new Throwable();} else {throw new Throwable();}
} catch(Throwable e) {
e.printStackTrace();
return e.getStackTrace();
}
}
/* standalone interface */
public static void main(String argv[]) {
equalsTests test = new equalsTests();
test.StackTraceElement2008();
}
public void init() {
StackTraceElement2008();
}
public void StackTraceElement2008() {
StackTraceElement[] first = getStackTraceElements(true);
StackTraceElement[] second = getStackTraceElements(false);
for(int i = 0; i < first.length; i++) {
for(int j = 0; j < second.length; j++) {
boolean res1 = first[i].equals(second[j]);
boolean res2 = equals(first[i].getFileName(), second[j].getFileName()) &&
(first[i].getLineNumber() == second[j].getLineNumber()) &&
equals(first[i].getClass(), second[j].getClass()) &&
equals(first[i].getMethodName(), second[j].getMethodName());
if (res1 != res2) {
System.err.println("first["+i+"]");
System.err.println("first[i].getFileName(): "+first[i].getFileName());
System.err.println("first[i].getLineNumber(): "+first[i].getLineNumber());
System.err.println("first[i].getClass(): "+first[i].getClass());
System.err.println("first[i].getMethodName(): "+first[i].getMethodName());
System.err.println("second["+j+"]");
System.err.println("second[j].getFileName(): "+second[j].getFileName());
System.err.println("second[j].getLineNumber() :"+second[j].getLineNumber());
System.err.println("second[j].getClass() :"+second[j].getClass());
System.err.println("second[j].getMethodName() :"+second[j].getMethodName());
System.err.println("res1: "+res1+" res2: "+res2);
System.err.println("failedStackTraceElement.equals");
return;
}
}
}
System.err.println("OKAY");
}
}
---------------------------------------------------------------------------
Code produces the following output:
For i=3 and j=4 according to java specification objects
should be equal, but StackTraceElement.equals returns false.
---------------------------------------------------------------------------
java.lang.Throwable
at equalsTests.getStackTraceElements(equalsTests.java:33)
at equalsTests.StackTraceElement2008(equalsTests.java:70)
at equalsTests.init(equalsTests.java:47)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.Throwable
at equalsTests.getStackTraceElements(equalsTests.java:33)
at equalsTests.StackTraceElement2008(equalsTests.java:71)
at equalsTests.init(equalsTests.java:47)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
first[3]
first[i].getFileName(): null
first[i].getLineNumber(): -1
first[i].getClass(): class java.lang.StackTraceElement
first[i].getMethodName(): run
second[4]
second[j].getFileName(): null
second[j].getLineNumber() :-1
second[j].getClass() :class java.lang.StackTraceElement
second[j].getMethodName() :run
res1: false res2: true
failedStackTraceElement.equals
---------------------------------------------------------------------------
Test output:
=============
StackTraceElement2008: Failed. StackTraceElement.equals
Specific Machine Info:
=====================
Hostname : linux-2
Os: win2000
======================================================================