[jbosstools-issues] [JBoss JIRA] (JBIDE-14518) Arquillian Validation does not take class tree into consideration

Snjezana Peco (JIRA) jira-events at lists.jboss.org
Wed Oct 16 13:09:01 EDT 2013


    [ https://issues.jboss.org/browse/JBIDE-14518?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12815477#comment-12815477 ] 

Snjezana Peco edited comment on JBIDE-14518 at 10/16/13 1:07 PM:
-----------------------------------------------------------------

This issue happens because the Eclipse compiler (as well as the JDK javac compiler) ignores unused fields.
Have a look at the following class:

{code}
@RunWith(Arquillian.class)
public class Test2 {

	@Inject Manager manager; // public class Manager extends SuperManager{@Inject public Handler handler;}
	
	@Deployment
	public static Archive<?> createDeployment() {
		WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
				.addClasses( Manager.class)
				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
		return archive;
	}
	
	@Test
	public void testInjected() {
		// System.out.println(manager);
		fail("Not yet implemented");
	}
}
{code}

Since the manager field isn't used, the compiler ignores it although it isn't resolved (SuperManager.class and Handler.class aren't included into the classpath).
That would be correct if the field wasn't annotated and instantiated by a container at runtime.
If you uncomment the "System.out.println(manager)" line, the compiler will recognize that SuperManager.class is required because the manager field isn't unused anymore.
However, it won't recognize the Handler class is required since the Manager.handler field is now unused.
The compiler internally marks such a field as unresolved what I utilized to make a workaround.
Another solution would be to try to use a Java dependency/analysis tools (asm, for instance).

                
      was (Author: snjeza):
    This issue happens because the Eclipse compiler (as well as the JDK javac compiler) ignores unused fields.
Have a look at the following class:

{code}
@RunWith(Arquillian.class)
public class Test2 {

	@Inject Manager manager; // public class Manager extends SuperManager{@Inject public Handler handler;}
	
	@Deployment
	public static Archive<?> createDeployment() {
		WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
				.addClasses( Manager.class)
				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
		return archive;
	}
	
	@Test
	public void testInjected() {
		// System.out.println(manager);
		fail("Not yet implemented");
	}
}
{code}

Since the manager field isn't used, the compiler ignores it although it isn't resolved (SuperManager.class and Handler.class aren't included into the classpath).
That would be correct if the field wasn't annotated and instantiated by a container at runtime.
If you uncomment the "System.out.println(manager)" line, the compiler will recognize that SuperManager.class is required because the manager field isn't unused anymore.
However, it won't recognize the Handler class is required since the Manager.handler field is now unused.
The compiler internally marks such a field as resolved what I utilized to make a workaround.
Another solution would be to try to use a Java dependency/analysis tools (asm, for instance).

                  
> Arquillian Validation does not take class tree into consideration
> -----------------------------------------------------------------
>
>                 Key: JBIDE-14518
>                 URL: https://issues.jboss.org/browse/JBIDE-14518
>             Project: Tools (JBoss Tools)
>          Issue Type: Sub-task
>          Components: testing-tools
>            Reporter: Aslak Knutsen
>            Assignee: Snjezana Peco
>              Labels: new_and_noteworthy
>             Fix For: 4.2.0.Alpha1
>
>
> Only classes used directly from the TestClass seems to be caught by the validation.
> {code}
> class Manager extends SuperManager {
>   @Inject Handler handler;
> }
> @Deployment
> public static WebArchive deploy() {
>   return ShrinkWrap.create(WebArchive.class).addClass(Manager.class);
> }
> {code}
> Expected validation error on missing Handler and SuperManager as well.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jbosstools-issues mailing list