-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SingleImplPass doesn't handle annotations correctly #734
Comments
Very interesting. The reason we did not run into this is likely because we nuke those annotations with If we do want to make sure
The motivation for merging annotations was that if we don't do this, we would drop annotations inadvertently, I think. |
I have two solutions in mind:
I'm working on (2) right now since it seems like it will give the most gains while also being safe in this particular case. |
SG. We can add a fix for #1. |
SingleImplPass searches for interfaces with only a single implementor class and then merges the interface into the implementor. This includes merging annotations, in particular the EnclosingClass, EnclosingMethod, InnerClass, and MemberClasses annotations.
However, those 4 names annotations have specific relations to each other with EnclosingClass and EnclosingMethod being explicitly mutually exclusive. A simple merge of the annotations leads to a break in the annotation's relationship and leaves dangling pointers to deleted interfaces.
This is particularly bad in the case of
java.lang.Class.getCanonicalName()
since the canonical name of an inner class is defined relate to its outer class which is found using the EnclosingClass annotation, which means thatSingleImplPass
can implicitly change the canonical name of single implementor classes.Example:
In this situation, interface C should be merged into single implementor class B. However, after
SingleImplPass
merges C into B, B now inherits C's EnclosingClass and InnerClass annotations which changes B's canonical name fromsecond.pkg.demo.B
tomy.first.pkg.A.B
.I am not sure what the proper fix should be, but at the very least when the relationship between the 4 annotations changed by
SingleImplPass
should be maintained by pointing the annotations away from deleted interfaces and to their single implementor class.In my mind, it should be possible to drop the EnclosingClass, EnclosingMethod, and InnerClass annotations during the merge since it does not make sense to make the single implementor an inner class of the deleted interface's outer class.
The text was updated successfully, but these errors were encountered: