Sunday, March 23, 2014

Re: CssResource interface conflict?

I found it ;)     (some grey hair further)

the bug is in the method: ClassRenamer.endVisit(CssSelector x, Context ctx), in this line:
      actualReplacements.put(method, obfuscatedClassName);

Because of the reuse of the parent class HasOuterContainerStyle, the method variable is the same when using an @Import that also extends from HasOuterContainerStyle such that it overrides any existing OuterContainer style in the above actualReplacements.

Example in my case I have:
public interface SubscribeStyle extends CssResource, HasOuterContainerStyle {
}
 
public interface SubscribeResources extends ClientBundle {
@Import(LinkButtonStyle.class)
SubscribeStyle style();
}
 
@ImportedWithPrefix("LinkButton")
public interface LinkButtonStyle extends CssResource, HasOuterContainerStyle {
}
 
Subscribe.css:
.OuterContainer .LinkButton-OuterContainer {
float: right;
}


Note how both SubscribeStyle and LinkButtonStyle extend HasOuterContainerStyle which will result LinkButton-OuterContainer style overriding the original SubscribeStyle-OuterContainer style.
This happens when the imports are being processed in the  method: ClassRenamer.endVisit(CssSelector x, Context ctx)
It will find the LinkButton-OuterContainer and will store this in the map: actualReplacements: 
 actualReplacements.put(method, obfuscatedClassName)

Because the method used as key, is actually the same as that of SubscribeStyle-OuterContainer, it will override this latter one.
Note: the method is: HasOuterContainerStyle.outerContainer()..

Solution: ensure the key method in the map is unique under these circumstances..
But I am not sure how, as it's an interface method and changing the key might have too big of an impact on other code... The signature:
  private final Map<JMethod, String> actualReplacements = new IdentityHashMap<JMethod, String>();

Maybe it could be wrapped by a wrapper class that holds the orginal JMethod with an identity that equals that of the JMethod and import prefix.
Something like this:
class JMethodHolder {
 private JMethod method;
 private String prefix;
 .. constructors..
 ...hashCode and equals containing method and prefix..
 }

I have put it in the issue tracker under nr: 8642
 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment