Skip to content
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

Add a helper method to judge whether a given instance has been enhanced #1340

Closed
wants to merge 3 commits into from

Conversation

ShaneXiangH
Copy link

Solve issue #187

I add a marker interface in the file bytecodeGen.java

Each time a new Enhanced class is generated, it also generate a instance with marker interface.

@mcculls
Copy link
Contributor

mcculls commented May 31, 2020

Marker interfaces don't play well with modular systems like JPMS because the enhanced class needs to be able to access both the type it's enhancing and the marker interface, which is likely defined in a different classloader. This means you need to use a "bridge" classloader for the enhanced class which introduces a lot of extra complexity.

The new enhancer code in #1298 deliberately avoids introducing Guice-specific types in the enhanced class, which keeps the classloading very simple. Introducing a Guice-specific marker interface here would undo this work and mean we'd need to bring back bridge class-loading.

I'd also question what this marker interface would be used for - ie. why do clients need to know if the type has been enhanced or not, and why can't they look at the class name or hierarchy (Guice uses a naming convention for enhanced types which makes this relatively straightforward.)

An alternative solution would be to introduce a static helper that returned whether a given class or instance has been enhanced. This could use the naming convention as described above to decide and would avoid the need to introduce a dependency back to Guice from the enhanced type.

@ShaneXiangH
Copy link
Author

mcculls thank you. I think you are right.

I added such a static helper method in Guice.java and this method can returns whether the given instance has been enhanced. In addition, I added a testing method in BytecodeGenTest.java

@ShaneXiangH ShaneXiangH changed the title I let all enhanced classes implement a marker interface Add a helper method to judge whether a given instance has been enhanced Jun 1, 2020
@alex-courtis
Copy link

Guice#isGuiceEnhanced successfully passes #testIsEnhancedJudge on java 1.8 maven 3.2.5.

I wonder if we might add stripGuiceMarksFromClassName to this PR, as per #187 (comment)
There is a real world use case for it and the test is almost the same.

copybara-service bot pushed a commit that referenced this pull request Apr 18, 2023
…eturning the unenahnced version).

(Also changes the classname suffix to be a hex string instead of an int, which had previously included a leading negative sign, which was weird.)

Fixes #1340 & fixes #187.

PiperOrigin-RevId: 525256080
copybara-service bot pushed a commit that referenced this pull request Apr 18, 2023
…eturning the unenhanced version).

(Also changes the classname suffix to be a hex string instead of an int, which had previously included a leading negative sign, which was weird.)

Fixes #1340 & fixes #187.

PiperOrigin-RevId: 525256080
copybara-service bot pushed a commit that referenced this pull request Apr 22, 2023
…eturning the unenhanced version).

(Also changes the classname suffix to be a hex string instead of an int, which had previously included a leading negative sign, which was weird.)

Fixes #1340 & fixes #187.

PiperOrigin-RevId: 525256080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants