java.lang.IllegalArgumentException: wrong number of arguments

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalArgumentException: wrong number of arguments

Pierre Ernst
I found an issue at these 2 lines:

https://github.com/apache/activemq/blob/e2b4ca2c59a316be91cf391c758a10e518dd3a1f/activemq-broker/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java#L244

https://github.com/apache/activemq/blob/e2b4ca2c59a316be91cf391c758a10e518dd3a1f/activemq-broker/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java#L256

the test:
paramTypes.length != 0
should be replaced by:
paramTypes.length ==1

Otherwise, the code might attempt to call a constructor/setter for which
the 1st parameter is a String (but having potentially other parameters)
with only a single value.

e.g. imagine this class:

public class MyClass {

  public MyClass (String s, int i) {
  }

  public MyClass (String s) {
  }
}

Depending on the order in the bytecode, the 1st constructor (String, int)
might be selected and the class will be initialized with constructors[i].
newInstance(new Object[]{name}), resulting
in java.lang.IllegalArgumentException: wrong number of arguments

Hoping it helps


--
Pierre Ernst
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalArgumentException: wrong number of arguments

christopher.l.shannon
Thanks for pointing that out, this change makes sense to me.  I fixed it
here https://issues.apache.org/jira/browse/AMQ-6337

On Thu, Jun 23, 2016 at 3:34 PM, Pierre Ernst <[hidden email]>
wrote:

> I found an issue at these 2 lines:
>
>
> https://github.com/apache/activemq/blob/e2b4ca2c59a316be91cf391c758a10e518dd3a1f/activemq-broker/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java#L244
>
>
> https://github.com/apache/activemq/blob/e2b4ca2c59a316be91cf391c758a10e518dd3a1f/activemq-broker/src/main/java/org/apache/activemq/security/DefaultAuthorizationMap.java#L256
>
> the test:
> paramTypes.length != 0
> should be replaced by:
> paramTypes.length ==1
>
> Otherwise, the code might attempt to call a constructor/setter for which
> the 1st parameter is a String (but having potentially other parameters)
> with only a single value.
>
> e.g. imagine this class:
>
> public class MyClass {
>
>   public MyClass (String s, int i) {
>   }
>
>   public MyClass (String s) {
>   }
> }
>
> Depending on the order in the bytecode, the 1st constructor (String, int)
> might be selected and the class will be initialized with constructors[i].
> newInstance(new Object[]{name}), resulting
> in java.lang.IllegalArgumentException: wrong number of arguments
>
> Hoping it helps
>
>
> --
> Pierre Ernst
>