Skip to content

Commit

Permalink
Issue #1135 - Avoid allocations from Method.getParameterTypes() if po…
Browse files Browse the repository at this point in the history
…ssible

Signed-off-by: dreis2211 <christoph.dreis@freenet.de>
(cherry picked from commit 16334c1)
  • Loading branch information
dreis2211 authored and janbartel committed Nov 29, 2016
1 parent dd76ed2 commit 9b0f6b1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void doHandle(Class clazz)
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void doHandle(Class clazz)
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void handleMethod(Class<?> clazz, Method method)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public MBeanAttributeInfo defineAttribute(Method method, ManagedAttribute attrib
{

// 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)
{
Expand All @@ -682,7 +682,7 @@ public MBeanAttributeInfo defineAttribute(Method method, ManagedAttribute attrib
}

// 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void toJSON(Object obj, Output out)
{
Method m=methods[i];
if (!Modifier.isStatic(m.getModifiers()) &&
m.getParameterTypes().length==0 &&
m.getParameterCount()==0 &&
m.getReturnType()!=null &&
m.getDeclaringClass()!=Object.class)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void init()
if (!Modifier.isStatic(m.getModifiers()) && m.getDeclaringClass()!=Object.class)
{
String name=m.getName();
switch(m.getParameterTypes().length)
switch(m.getParameterCount())
{
case 0:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static boolean isJavaBeanCompliantSetter (Method method)
if (!method.getName().startsWith("set"))
return false;

if (method.getParameterTypes().length != 1)
if (method.getParameterCount() != 1)
return false;

return true;
Expand Down
12 changes: 6 additions & 6 deletions jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public static Object call(Class<?> oClass, String methodName, Object obj, Object
{
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;
Expand All @@ -535,7 +535,7 @@ public static Object call(Class<?> oClass, String methodName, Object obj, Object
{
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;
Expand Down Expand Up @@ -569,10 +569,10 @@ public static Object construct(Class<?> klass, Object[] arguments) throws Invoca
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
Expand All @@ -597,10 +597,10 @@ public static Object construct(Class<?> klass, Object[] arguments, Map<String, O
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
Expand Down

0 comments on commit 9b0f6b1

Please sign in to comment.