From 9b0f6b1fd588b999b3d3af309349e202eb998880 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 28 Nov 2016 21:14:21 +0100 Subject: [PATCH] Issue #1135 - Avoid allocations from Method.getParameterTypes() if possible Signed-off-by: dreis2211 (cherry picked from commit 16334c1893cc45a6a811cc7c6f2552a861643dac) --- .../annotations/PostConstructAnnotationHandler.java | 2 +- .../annotations/PreDestroyAnnotationHandler.java | 2 +- .../jetty/annotations/ResourceAnnotationHandler.java | 2 +- .../main/java/org/eclipse/jetty/jmx/ObjectMBean.java | 4 ++-- .../eclipse/jetty/util/ajax/JSONObjectConvertor.java | 2 +- .../eclipse/jetty/util/ajax/JSONPojoConvertor.java | 2 +- .../org/eclipse/jetty/util/IntrospectionUtil.java | 2 +- .../main/java/org/eclipse/jetty/util/TypeUtil.java | 12 ++++++------ 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PostConstructAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PostConstructAnnotationHandler.java index a57ebeb637d..4ff31a6a579 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PostConstructAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PostConstructAnnotationHandler.java @@ -52,7 +52,7 @@ public class PostConstructAnnotationHandler extends AbstractIntrospectableAnnota Method m = (Method)methods[i]; if (m.isAnnotationPresent(PostConstruct.class)) { - if (m.getParameterTypes().length != 0) + if (m.getParameterCount() != 0) throw new IllegalStateException(m+" has parameters"); if (m.getReturnType() != Void.TYPE) throw new IllegalStateException(m+" is not void"); diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PreDestroyAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PreDestroyAnnotationHandler.java index 56f805f07c6..3172fc6a5ad 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PreDestroyAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/PreDestroyAnnotationHandler.java @@ -51,7 +51,7 @@ public class PreDestroyAnnotationHandler extends AbstractIntrospectableAnnotatio Method m = (Method)methods[i]; if (m.isAnnotationPresent(PreDestroy.class)) { - if (m.getParameterTypes().length != 0) + if (m.getParameterCount() != 0) throw new IllegalStateException(m+" has parameters"); if (m.getReturnType() != Void.TYPE) throw new IllegalStateException(m+" is not void"); diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java index 45f4dc695d3..47bd713e882 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ResourceAnnotationHandler.java @@ -257,7 +257,7 @@ public class ResourceAnnotationHandler extends AbstractIntrospectableAnnotationH return; } - if (method.getParameterTypes().length != 1) + if (method.getParameterCount() != 1) { LOG.warn("Skipping Resource annotation on "+clazz.getName()+"."+method.getName()+": invalid java bean, not single argument to method"); return; diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java index 38cf6f88d18..5376b409934 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java @@ -663,7 +663,7 @@ public class ObjectMBean implements DynamicMBean { // look for a declared setter - if (methods[m].getName().equals(declaredSetter) && methods[m].getParameterTypes().length == 1) + if (methods[m].getName().equals(declaredSetter) && methods[m].getParameterCount() == 1) { if (setter != null) { @@ -682,7 +682,7 @@ public class ObjectMBean implements DynamicMBean } // look for a setter - if ( methods[m].getName().equals("set" + uName) && methods[m].getParameterTypes().length == 1) + if ( methods[m].getName().equals("set" + uName) && methods[m].getParameterCount() == 1) { if (setter != null) { diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java index c19be74d452..5513f52d99d 100644 --- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java +++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONObjectConvertor.java @@ -80,7 +80,7 @@ public class JSONObjectConvertor implements JSON.Convertor { Method m=methods[i]; if (!Modifier.isStatic(m.getModifiers()) && - m.getParameterTypes().length==0 && + m.getParameterCount()==0 && m.getReturnType()!=null && m.getDeclaringClass()!=Object.class) { diff --git a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java index a489d3f2404..88e5ce1e59e 100644 --- a/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java +++ b/jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSONPojoConvertor.java @@ -116,7 +116,7 @@ public class JSONPojoConvertor implements JSON.Convertor if (!Modifier.isStatic(m.getModifiers()) && m.getDeclaringClass()!=Object.class) { String name=m.getName(); - switch(m.getParameterTypes().length) + switch(m.getParameterCount()) { case 0: diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IntrospectionUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IntrospectionUtil.java index 5f724cac2e3..2f4464a450a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/IntrospectionUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IntrospectionUtil.java @@ -44,7 +44,7 @@ public class IntrospectionUtil if (!method.getName().startsWith("set")) return false; - if (method.getParameterTypes().length != 1) + if (method.getParameterCount() != 1) return false; return true; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index 0173e55723d..5f31f9841a7 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -511,7 +511,7 @@ public class TypeUtil { if (!method.getName().equals(methodName)) continue; - if (method.getParameterTypes().length != arg.length) + if (method.getParameterCount() != arg.length) continue; if (Modifier.isStatic(method.getModifiers()) != (obj == null)) continue; @@ -535,7 +535,7 @@ public class TypeUtil { if (!method.getName().equals(methodName)) continue; - if (method.getParameterTypes().length != arg.length+1) + if (method.getParameterCount() != arg.length+1) continue; if (!method.getParameterTypes()[arg.length].isArray()) continue; @@ -569,10 +569,10 @@ public class TypeUtil if (arguments == null) { // null arguments in .newInstance() is allowed - if (constructor.getParameterTypes().length != 0) + if (constructor.getParameterCount() != 0) continue; } - else if (constructor.getParameterTypes().length != arguments.length) + else if (constructor.getParameterCount() != arguments.length) continue; try @@ -597,10 +597,10 @@ public class TypeUtil if (arguments == null) { // null arguments in .newInstance() is allowed - if (constructor.getParameterTypes().length != 0) + if (constructor.getParameterCount() != 0) continue; } - else if (constructor.getParameterTypes().length != arguments.length) + else if (constructor.getParameterCount() != arguments.length) continue; try