ikedam commented on Bug JENKINS-21664

I finally found the root cause.
Upcasting in codes cause class loading:

public void doSomething()
{
  if(Jenkins.getInstance().getPlugin("dependee"))
  {
    Derived d = somemethod();
    Base b = (Derive)d; // <- This causes load Derive even not executing doSomething().
  }
}

and in Java6,

for(Base b: getDerivedList())
{
  someMethodForBase(b);
}

This code is compiled as following:

for(Derived b: getDerivedList()) // <- Base is changed to Derived
{
  someMethodForBase(b); // Here causes upcasting.
}

There are some exceptions:

  • Upcasting to Object does not cause class loading.
  • Conversion between generic types does not cause class loading. (as generic types are completely ignored in execution time)
    • Base b = derivedList.get( i ); does not cause class loading.
    • Base b = derivedIterator.next(); does not cause class loading.
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

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to