While developing a Java application under Eclipse I got the warning about "method/value accessed via a synthetic method". The solution was simply changing a private access modifier to a default level.
That left me wondering: what's the penalty on using a synthetic method? There is some? I assume so as the compiler/Eclipse raises the warning, but it's something so relevant or something that could be safely ignored?
I've not seen this information around here, so I'm asking.
Eclipse is warning you that you may be exposing information you think is private. Synthetic accessors can be exploited by malicious code as demonstrated below.
If your code needs to run in a secure VM, it may be unwise to use inner classes. If you can use reflection and have full access to everything, synthetic accessors are unlikely to make a measurable difference.
For example, consider this class:
The signature for
Foo
is actually:access$000
is generated automatically to let the separate classBar
accessbaz
and will be marked with the Synthetic attribute. The precise names generated are implementation dependent. Regular compilers won't let you compile against this method, but you can generate your own classes using ASM (or similar) like this:This creates a simple class called
Spy
that will allow you to callaccess$000
:Using this, you can inspect the value of
baz
without reflection or any method exposing it.The
Spy
implementation requires that it be in the same package asFoo
and thatFoo
isn't in a sealed JAR.