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

Unexpected synthethic ImmutableMy$1.class compiled #1

Closed
augustotravillio opened this issue Dec 27, 2013 · 2 comments
Closed

Unexpected synthethic ImmutableMy$1.class compiled #1

augustotravillio opened this issue Dec 27, 2013 · 2 comments

Comments

@augustotravillio
Copy link
Member

Hi, I've made simplest possible immutable class with builder and got following classes in jar

My.class
ImmutableMy.class
ImmutableMy$Builder.class
ImmutableMy$1.class

(on jdk7 u45, using maven/javac)
Could we somehow get rid of additional class ImmutableMy$1.class being compiled? Is this somehow related to inner class private access bridge?

@elucash
Copy link
Member

elucash commented Jan 3, 2014

Having investigated that I've found that this class is a synthetic access-bridge class. Private fields of builder object accessed in immutable class constructor, this somehow require this unwanted class to be generated
Curiously, but Eclipse compiler do not require such class, probably static accessor methods are enough for ECJ.

My current idea is to leave this as is for a while, but we could revise how code is generated in that place.
Long ago there we no builder object passing to immutable class constructor, constructors with high count of parameters was used where all attributes was passed separately, so builder just need to access private constructor of enclosing class (via simple synthetic static method) -- this will probably wont require additional class by Javac

JFYI at that time we fought checkstyle rules where high arity method and constructors were not allowed, don't know
if it is important now since we moved to annotation processing, so generated-sources could be made skipped if check-style is used.

Happy new year!

@elucash elucash added the wontfix label Sep 7, 2014
@elucash
Copy link
Member

elucash commented Sep 7, 2014

  • Immutable constructor accesses private fields of Builder
  • Builder access private constructor of Immutable

ECJ creates package-private static synthetic methods to compile this
Javac might generate whole synthetic class to bridge this

Either we relax access restriction and expose package-private methods/constructor in generated code.
Or we will live with whatever compiler generates in hope that runtime inlines everything it can.

Currently I do not want to expose package-private methods. Closing as won't fix, but we could return to this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants