-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.4.2
Name: jl125535 Date: 09/04/2003
A DESCRIPTION OF THE REQUEST :
Our application uses serialized Java objects to store configuration information and RMI for client-server-communication.
java.io classes ObjectStreamClass, ObjectInputStream, ObjectOutputStream call java.lang.Class methods getDeclaredMethod() and getDeclaredField() looking for the special serialization methods (e.g. readObject, writeObject, readResolve, writeReplace) and fields (e.g. serialVersionUID, serialPersistentFields) causing lots of NoSuchFieldExceptions and NoSuchMethodExceptions to be thrown.
I modified java.lang.Throwable.java (see attached source code and method _logThrowable()) to print information about NoSuchMethodExceptions and NoSuchFieldExceptions to stdout. Compile it and put the .class file in a newly created empty directory-tree c:\jdkpatch\java\lang.
When starting JDK's serialization-sample EvolutionExampleOriginalClass
java -Xbootclasspath/p:c:\jdkpatch EvolutionExampleOriginalClass -s
14 instances of NoSuchMethod/FieldException are thrown.
In our application, making heavy use of serialization, thousands of these exceptions are thrown during startup.
JUSTIFICATION :
Throwing and catching exceptions slows down the application. In addition to that for keeping stack-traces objects need to be created and garbage-collected. This has an impact on application performance.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I suggest using return-codes instead of exceptions wherever possible. e.g. java.lang.Class.getDeclaredMethod() could simply return null if the method was not found.
---------- BEGIN SOURCE ----------
My changes to Throwable.java:
- added new static variable "count"
- added new method "_logThrowable" (please note that the method's
implementation is slightly different in incident 201376)
- called method "_logThrowable" from the constructors
Here is the code:
private static int count = 0;
private void _logThrowable()
{
if (getClass() == NoSuchMethodException.class
|| getClass() == NoSuchFieldException.class)
{
count++;
System.out.println("NoSuchMethod/FieldException #" + count);
printStackTrace();
}
}
public Throwable() {
fillInStackTrace();
_logThrowable();
}
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
_logThrowable();
}
public Throwable(String message, Throwable cause) {
fillInStackTrace();
detailMessage = message;
this.cause = cause;
_logThrowable();
}
public Throwable(Throwable cause) {
fillInStackTrace();
detailMessage = (cause==null ? null : cause.toString());
this.cause = cause;
_logThrowable();
}
---------- END SOURCE ----------
(Incident Review ID: 201379)
======================================================================
A DESCRIPTION OF THE REQUEST :
Our application uses serialized Java objects to store configuration information and RMI for client-server-communication.
java.io classes ObjectStreamClass, ObjectInputStream, ObjectOutputStream call java.lang.Class methods getDeclaredMethod() and getDeclaredField() looking for the special serialization methods (e.g. readObject, writeObject, readResolve, writeReplace) and fields (e.g. serialVersionUID, serialPersistentFields) causing lots of NoSuchFieldExceptions and NoSuchMethodExceptions to be thrown.
I modified java.lang.Throwable.java (see attached source code and method _logThrowable()) to print information about NoSuchMethodExceptions and NoSuchFieldExceptions to stdout. Compile it and put the .class file in a newly created empty directory-tree c:\jdkpatch\java\lang.
When starting JDK's serialization-sample EvolutionExampleOriginalClass
java -Xbootclasspath/p:c:\jdkpatch EvolutionExampleOriginalClass -s
14 instances of NoSuchMethod/FieldException are thrown.
In our application, making heavy use of serialization, thousands of these exceptions are thrown during startup.
JUSTIFICATION :
Throwing and catching exceptions slows down the application. In addition to that for keeping stack-traces objects need to be created and garbage-collected. This has an impact on application performance.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I suggest using return-codes instead of exceptions wherever possible. e.g. java.lang.Class.getDeclaredMethod() could simply return null if the method was not found.
---------- BEGIN SOURCE ----------
My changes to Throwable.java:
- added new static variable "count"
- added new method "_logThrowable" (please note that the method's
implementation is slightly different in incident 201376)
- called method "_logThrowable" from the constructors
Here is the code:
private static int count = 0;
private void _logThrowable()
{
if (getClass() == NoSuchMethodException.class
|| getClass() == NoSuchFieldException.class)
{
count++;
System.out.println("NoSuchMethod/FieldException #" + count);
printStackTrace();
}
}
public Throwable() {
fillInStackTrace();
_logThrowable();
}
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
_logThrowable();
}
public Throwable(String message, Throwable cause) {
fillInStackTrace();
detailMessage = message;
this.cause = cause;
_logThrowable();
}
public Throwable(Throwable cause) {
fillInStackTrace();
detailMessage = (cause==null ? null : cause.toString());
this.cause = cause;
_logThrowable();
}
---------- END SOURCE ----------
(Incident Review ID: 201379)
======================================================================