-
Bug
-
Resolution: Withdrawn
-
P4
-
None
-
8, 11, 17, 20
-
None
-
generic
-
generic
Currently, the implementation of serialization makes use of `Class.getDeclaredMethod(String,Class<?>...)` to get a reference to the special serialization "magic" methods, like `writeObject` or `writeReplace`.
However, this getter fails to return all the methods with the given name and parameter types. More specifically, it returns the one with the most specific return type, or an arbitrary one if no most specific one exists. Consequently, serialization might fail to locate the "magic" methods even if they exists in the class.
This is not a real problem for java source classes, but might be one for other JVM languages.
Since there's no `Class.getDeclaredMethod()` variant that accepts an additional `Class<?>` parameter for the return type, one workaround is to use `Class.getDeclaredMethods()` and retrieve the correct one in the returned array.
Similarly for `Class.getDeclaredField()`.
Alternatively, a `Class.getDeclaredMethod(String,Class<?>, Class<?>...)` with an additional parameter for the return type could be added to `Class`.
However, this getter fails to return all the methods with the given name and parameter types. More specifically, it returns the one with the most specific return type, or an arbitrary one if no most specific one exists. Consequently, serialization might fail to locate the "magic" methods even if they exists in the class.
This is not a real problem for java source classes, but might be one for other JVM languages.
Since there's no `Class.getDeclaredMethod()` variant that accepts an additional `Class<?>` parameter for the return type, one workaround is to use `Class.getDeclaredMethods()` and retrieve the correct one in the returned array.
Similarly for `Class.getDeclaredField()`.
Alternatively, a `Class.getDeclaredMethod(String,Class<?>, Class<?>...)` with an additional parameter for the return type could be added to `Class`.
- links to
-
Review openjdk/jdk/15364