You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Kasun Gajasinghe <ka...@gmail.com> on 2011/08/15 09:25:13 UTC

ClassCastException in m-surefire-p in custom-built maven!

Hi,
We're very close to have the results.
maven-{clean,resources,compile}-plugin works as expected. Now, I'm at
[surefire:test {execution: default-test}] phase. Well, m-surefire-p is
giving me issues.

I'm getting a weird ClassCastException for
org.apache.maven.plugin.surefire.SurefirePlugin.
    "java.lang.ClassCastException:
org.apache.maven.plugin.surefire.SurefirePlugin cannot be cast to
org.apache.maven.plugin.Mojo"

It's just basics. Don't understand why it fails. SurefirePlugin class
implements (actually, by it's parent's parent) the Mojo interface. So,
this class should be able to cast to Mojo, right? But this cast in
DefaultPluginManager [1] fails.
    plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE,
mojoDescriptor.getRoleHint() );

The SurefirePlugin Mojo is somewhat same as other mojos such as
CleanMojo with some differences I noticed.
  * SurefirePluginMojo has an additional abstraction layer named
AbstractSurefireMojo class.
  * SurefirePlugin mojo class name does not end with *Mojo like all
the mojos are. (Not sure whether this doesn't even need to consider.
May be there's a class filtering mechanism?)

Would these play a part here?
Please let me know if you have any idea worth trying. The error log is
given below. mvn -X output is at [2]

[1] http://www.jarvana.com/jarvana/view/org/apache/maven/maven-core/2.2.1/maven-core-2.2.1-sources.jar!/org/apache/maven/plugin/DefaultPluginManager.java?format=ok
[2] http://pastebin.com/gR6D2aLb

The error log -

[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org.apache.maven.plugin.surefire.SurefirePlugin cannot be cast
to org.apache.maven.plugin.Mojo
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
java.lang.ClassCastException:
org.apache.maven.plugin.surefire.SurefirePlugin cannot be cast to
org.apache.maven.plugin.Mojo
	at org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(DefaultPluginManager.java:652)
	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:468)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
	at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)


Thanks,
--Kasun

-- 
~~~*******'''''''''''''*******~~~
Kasun Gajasinghe,
University of Moratuwa,
Sri Lanka.
Blog: http://blog.kasunbg.org
Twitter: http://twitter.com/kasunbg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: ClassCastException in m-surefire-p in custom-built maven!

Posted by Kasun Gajasinghe <ka...@gmail.com>.
On Mon, Aug 15, 2011 at 1:05 PM, Barrie Treloar <ba...@gmail.com> wrote:
> On Mon, Aug 15, 2011 at 4:55 PM, Kasun Gajasinghe <ka...@gmail.com> wrote:
>> Hi,
>> We're very close to have the results.
>> maven-{clean,resources,compile}-plugin works as expected. Now, I'm at
>> [surefire:test {execution: default-test}] phase. Well, m-surefire-p is
>> giving me issues.
>>
>> I'm getting a weird ClassCastException for
>> org.apache.maven.plugin.surefire.SurefirePlugin.
>>    "java.lang.ClassCastException:
>> org.apache.maven.plugin.surefire.SurefirePlugin cannot be cast to
>> org.apache.maven.plugin.Mojo"
>
> I'm no expert in this particular error, but I thought I'd throw out
> that ClassCastExceptions also arise from ClassLoader issues as the
> same class loaded via two different class loaders are considered
> different and will give ClassCastExceptions.
> Perhaps you are running into this.

Barrie,
Indeed, it's probably due to a ClassLoader issue. I'm gonna look in to
this path further. But I doubt it's because of the same class in two
places because every Jar is loaded under highly controlled
environment. And, there's only one version of *surefire-* jars (2.9,
the latest) installed. There are two SurefirePlugin classes in
m-surefire-p, but they belong to two different packages.

I looked at the possible classloader issues causing
classcastexceptions [1]. There are three possibilities. But, I don't
see anything applies to this case since we know that it works fine in
the official distribution! I should read it again.

If you have any other possibilities popped up in your head, just let me know!

Thanks,
--Kasun

[1] http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rtrb_classload_viewer.html

-- 
~~~*******'''''''''''''*******~~~
Kasun Gajasinghe,
University of Moratuwa,
Sri Lanka.
Blog: http://blog.kasunbg.org
Twitter: http://twitter.com/kasunbg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: ClassCastException in m-surefire-p in custom-built maven!

Posted by Barrie Treloar <ba...@gmail.com>.
On Mon, Aug 15, 2011 at 4:55 PM, Kasun Gajasinghe <ka...@gmail.com> wrote:
> Hi,
> We're very close to have the results.
> maven-{clean,resources,compile}-plugin works as expected. Now, I'm at
> [surefire:test {execution: default-test}] phase. Well, m-surefire-p is
> giving me issues.
>
> I'm getting a weird ClassCastException for
> org.apache.maven.plugin.surefire.SurefirePlugin.
>    "java.lang.ClassCastException:
> org.apache.maven.plugin.surefire.SurefirePlugin cannot be cast to
> org.apache.maven.plugin.Mojo"

I'm no expert in this particular error, but I thought I'd throw out
that ClassCastExceptions also arise from ClassLoader issues as the
same class loaded via two different class loaders are considered
different and will give ClassCastExceptions.
Perhaps you are running into this.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org