HHH-11136 - Reduce memory consumption caused by Method.getParameterTypes()

This commit is contained in:
ChristophDreis 2016-09-27 09:08:41 +02:00
parent e3bee9eede
commit d2d947068d
11 changed files with 16 additions and 16 deletions

View File

@ -89,7 +89,7 @@ public class ProxyFactoryFactoryImpl implements ProxyFactoryFactory {
private static final MethodFilter FINALIZE_FILTER = new MethodFilter() {
public boolean isHandled(Method m) {
// skip finalize methods
return !( m.getParameterTypes().length == 0 && m.getName().equals( "finalize" ) );
return !( m.getParameterCount() == 0 && m.getName().equals( "finalize" ) );
}
};
@ -120,9 +120,9 @@ public class ProxyFactoryFactoryImpl implements ProxyFactoryFactory {
return System.identityHashCode( object );
}
final boolean hasGetterSignature = method.getParameterTypes().length == 0
final boolean hasGetterSignature = method.getParameterCount() == 0
&& method.getReturnType() != null;
final boolean hasSetterSignature = method.getParameterTypes().length == 1
final boolean hasSetterSignature = method.getParameterCount() == 1
&& ( method.getReturnType() == null || method.getReturnType() == void.class );
if ( name.startsWith( "get" ) && hasGetterSignature ) {

View File

@ -88,7 +88,7 @@ public class BlobProxy implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName();
final int argCount = method.getParameterTypes().length;
final int argCount = method.getParameterCount();
if ( "length".equals( methodName ) && argCount == 0 ) {
return getLength();

View File

@ -88,7 +88,7 @@ public class ClobProxy implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName();
final int argCount = method.getParameterTypes().length;
final int argCount = method.getParameterCount();
if ( "length".equals( methodName ) && argCount == 0 ) {
return getLength();

View File

@ -103,7 +103,7 @@ public class ResultSetWrapperProxy implements InvocationHandler {
}
// method should have arguments, and have same number as incoming arguments
if ( ! ( method.getParameterTypes().length > 0 && args.length == method.getParameterTypes().length ) ) {
if ( ! ( method.getParameterCount() > 0 && args.length == method.getParameterCount() ) ) {
return false;
}
@ -125,14 +125,14 @@ public class ResultSetWrapperProxy implements InvocationHandler {
* @throws NoSuchMethodException Should never happen, but...
*/
private Method locateCorrespondingColumnIndexMethod(Method columnNameMethod) throws NoSuchMethodException {
final Class[] actualParameterTypes = new Class[columnNameMethod.getParameterTypes().length];
final Class[] actualParameterTypes = new Class[columnNameMethod.getParameterCount()];
actualParameterTypes[0] = int.class;
System.arraycopy(
columnNameMethod.getParameterTypes(),
1,
actualParameterTypes,
1,
columnNameMethod.getParameterTypes().length - 1
columnNameMethod.getParameterCount() - 1
);
return columnNameMethod.getDeclaringClass().getMethod( columnNameMethod.getName(), actualParameterTypes );
}

View File

@ -94,7 +94,7 @@ public class SQLExceptionConverterFactory {
// First, try to find a matching constructor accepting a ViolatedConstraintNameExtracter param...
final Constructor[] ctors = converterClass.getDeclaredConstructors();
for ( Constructor ctor : ctors ) {
if ( ctor.getParameterTypes() != null && ctor.getParameterTypes().length == 1 ) {
if ( ctor.getParameterTypes() != null && ctor.getParameterCount() == 1 ) {
if ( ViolatedConstraintNameExtracter.class.isAssignableFrom( ctor.getParameterTypes()[0] ) ) {
try {
return (SQLExceptionConverter) ctor.newInstance( violatedConstraintNameExtracter );

View File

@ -421,7 +421,7 @@ public final class ReflectHelper {
private static Method getGetterOrNull(Class containerClass, String propertyName) {
for ( Method method : containerClass.getDeclaredMethods() ) {
// if the method has parameters, skip it
if ( method.getParameterTypes().length != 0 ) {
if ( method.getParameterCount() != 0 ) {
continue;
}
@ -555,7 +555,7 @@ public final class ReflectHelper {
for ( Method method : theClass.getDeclaredMethods() ) {
final String methodName = method.getName();
if ( method.getParameterTypes().length == 1 && methodName.startsWith( "set" ) ) {
if ( method.getParameterCount() == 1 && methodName.startsWith( "set" ) ) {
final String testOldMethod = methodName.substring( 3 );
final String testStdMethod = Introspector.decapitalize( testOldMethod );
if ( testStdMethod.equals( propertyName ) || testOldMethod.equals( propertyName ) ) {

View File

@ -36,7 +36,7 @@ public class JavassistProxyFactory implements ProxyFactory, Serializable {
private static final MethodFilter FINALIZE_FILTER = new MethodFilter() {
public boolean isHandled(Method m) {
// skip finalize methods
return !( m.getParameterTypes().length == 0 && m.getName().equals( "finalize" ) );
return !( m.getParameterCount() == 0 && m.getName().equals( "finalize" ) );
}
};

View File

@ -297,7 +297,7 @@ public abstract class AbstractServiceRegistryImpl
@SuppressWarnings({ "unchecked" })
private <T extends Service> void processInjection(T service, Method injectionMethod, InjectService injectService) {
if ( injectionMethod.getParameterTypes() == null || injectionMethod.getParameterTypes().length != 1 ) {
if ( injectionMethod.getParameterTypes() == null || injectionMethod.getParameterCount() != 1 ) {
throw new ServiceDependencyException(
"Encountered @InjectService on method with unexpected number of parameters"
);

View File

@ -31,7 +31,7 @@ public class BeanUtils {
}
final String getterName = sb.toString();
for ( Method m : bean.getClass().getMethods() ) {
if ( getterName.equals( m.getName() ) && m.getParameterTypes().length == 0 ) {
if ( getterName.equals( m.getName() ) && m.getParameterCount() == 0 ) {
return m;
}
}

View File

@ -136,7 +136,7 @@ public class CustomParameterized extends Suite {
for (FrameworkMethod each : methods) {
if (each.isPublic()) {
if (!each.isStatic()) {
if (getTestClass().getOnlyConstructor().getParameterTypes().length != 0) {
if (getTestClass().getOnlyConstructor().getParameterCount() != 0) {
throw new Exception("Method " + each.getMethod() + " is annotated with @Parameters, it is not static and there is no parameter-less constructor!");
}
}

View File

@ -123,7 +123,7 @@ public class TestClassMetadata {
}
private void validateCallbackMethod(Method method, CallbackType type, List<Throwable> errors) {
if ( method.getParameterTypes().length > 0 ) {
if ( method.getParameterCount() > 0 ) {
errors.add(
new InvalidMethodForAnnotationException(
type.buildTypeMarker() + " callback only valid on no-arg methods : "