0

I have the following class:

public class DefaultContainer extends AbstractContainer {

private JobBeanFactory jobBeanFactory;

private ScheduleManager scheduleManager;

/**
 * for local
 * @param classLoader
 * @param packagesToScan
 */
public DefaultContainer(ClassLoader classLoader, String packagesToScan) {
    super(classLoader, packagesToScan);
    this.jobBeanFactory = new DefaultJobBeanFactory();
    Configuration configuration = new Configuration(classLoader);
    this.scheduleManager = new DefaultScheduleManager(configuration, this.jobBeanFactory, getJobScanner().getJobDescriptorList());
}

/**
 * for remote
 * @param configuration
 * @param packagesToScan
 * @param jarUrls
 */
public DefaultContainer(Configuration configuration, String packagesToScan, String... jarUrls) {
    super(packagesToScan, jarUrls);
    this.jobBeanFactory = new DefaultJobBeanFactory();
    this.scheduleManager = new DefaultScheduleManager(configuration, this.jobBeanFactory, getJobScanner().getJobDescriptorList());
}


public ScheduleManager scheduleManager() {
    return scheduleManager;
}

}

Then, I use reflection to load and create a class instance.

Class<Container> containerClass = (Class<Container>) classLoader.loadClass("xxxxx.DefaultContainer");
Constructor<Container> containerConstructor = containerClass.getConstructor(Configuration.class, String.class, String[].class);
container = containerConstructor.newInstance(getConfiguration(), packagesToScan, new String[]{jarUrl});

But when executing a method of newInstance, then I get an exception:

com.zuoxiaolong.niubi.job.core.exception.NiubiException: java.lang.IllegalArgumentException: argument type mismatch
at com.zuoxiaolong.niubi.job.cluster.node.AbstractRemoteJobNode.createContainer(AbstractRemoteJobNode.java:100)
at com.zuoxiaolong.niubi.job.cluster.node.AbstractRemoteJobNode.getContainer(AbstractRemoteJobNode.java:67)
at com.zuoxiaolong.niubi.job.cluster.node.MasterSlaveNode.executeOperation(MasterSlaveNode.java:264)
at com.zuoxiaolong.niubi.job.cluster.node.MasterSlaveNode.access$1000(MasterSlaveNode.java:56)
at com.zuoxiaolong.niubi.job.cluster.node.MasterSlaveNode$3.childEvent(MasterSlaveNode.java:253)
at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:516)
at org.apache.curator.framework.recipes.cache.PathChildrenCache$5.apply(PathChildrenCache.java:510)
at org.apache.curator.framework.listen.ListenerContainer$1.run(ListenerContainer.java:92)
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:297)
at org.apache.curator.framework.listen.ListenerContainer.forEach(ListenerContainer.java:83)
at org.apache.curator.framework.recipes.cache.PathChildrenCache.callListeners(PathChildrenCache.java:507)
at org.apache.curator.framework.recipes.cache.EventOperation.invoke(EventOperation.java:35)
at org.apache.curator.framework.recipes.cache.PathChildrenCache$9.run(PathChildrenCache.java:759)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.zuoxiaolong.niubi.job.cluster.node.AbstractRemoteJobNode.createContainer(AbstractRemoteJobNode.java:98)
    ... 19 more

Can anyone help me?

7
  • I make sure the parameter types are all matched with [Configuration.class,String.class,String[].class] Commented Jan 20, 2016 at 9:42
  • Are you sure getConfiguration() returns the same Configuration class as the constructor's parameter? Have you checked packagesToScan is indeed a String? Commented Jan 20, 2016 at 9:46
  • Also you are explicitly casting your class as Class<Container>. If Container is a class, does it have a matching constructor? Commented Jan 20, 2016 at 9:50
  • Yes, I sure. I has debug the program , and look at the program's runtime detail.It does match. Commented Jan 20, 2016 at 10:11
  • I eval the expressions ,then all return true. etc. Configuration.class==getConfiguration().getClass,packagesToScan.getClass()==String.class. Commented Jan 20, 2016 at 10:30

1 Answer 1

1

Try to cast your String array to Object. It should help.

containerConstructor.newInstance(getConfiguration(), packagesToScan, (Object) new String[]{ jarUrl });

Here someone had the same problem:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.