8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

Reviewed-by: shade, rriggs, liach
This commit is contained in:
John Engebretson 2024-06-03 13:38:48 +00:00 committed by Aleksey Shipilev
parent 1c514b34c0
commit 27af19d921
4 changed files with 176 additions and 7 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -266,7 +266,7 @@ public final class Constructor<T> extends Executable {
*/
@Override
public Class<?>[] getParameterTypes() {
return parameterTypes.clone();
return parameterTypes.length == 0 ? parameterTypes : parameterTypes.clone();
}
/**
@ -292,10 +292,9 @@ public final class Constructor<T> extends Executable {
*/
@Override
public Class<?>[] getExceptionTypes() {
return exceptionTypes.clone();
return exceptionTypes.length == 0 ? exceptionTypes : exceptionTypes.clone();
}
/**
* {@inheritDoc}
* @throws GenericSignatureFormatError {@inheritDoc}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -315,7 +315,7 @@ public final class Method extends Executable {
*/
@Override
public Class<?>[] getParameterTypes() {
return parameterTypes.clone();
return parameterTypes.length == 0 ? parameterTypes: parameterTypes.clone();
}
/**
@ -342,7 +342,7 @@ public final class Method extends Executable {
*/
@Override
public Class<?>[] getExceptionTypes() {
return exceptionTypes.clone();
return exceptionTypes.length == 0 ? exceptionTypes : exceptionTypes.clone();
}
/**