On Thu, 6 Jan 2022 16:38:05 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> `Executable.getParameterTypes()` creates a copy of underlying array which is >> redundant in trusted code when we are sure the action is read-only. > > src/java.base/share/classes/java/lang/reflect/Executable.java line 313: > >> 311: // getParameterTypes(). >> 312: if (!genericInfo) { >> 313: return getSharedParameterTypes(); > > Since this returns the trusted array it delegates responsibility to the > callers of `getAllGenericParameterTypes` to not mutate or further expose/leak > the parameter type array. This needs to at least be called out in the method > specification. The comment here needs to be updated, as well. Is the added > fragility in this case worth the performance win? I agree about the spec and comment. I think we have nothing to worry about in this case as `Executable` is sealed and `getAllGenericParameterTypes()` is package-private, so it never gets out of JDK codebase. As of its current usage we only read from returned `Type[]`. Lot's of frameworks utilize reflection, so I think we should try to make it as fast as possible ------------- PR: https://git.openjdk.java.net/jdk/pull/6782