Litho: NoSuchFieldError: savedParameterNames

Created on 28 Dec 2017  Â·  9Comments  Â·  Source: facebook/litho

There is a reference to com.sun.tools.javac.code.Symbol.MethodSymbol.savedParameterNames in MethodExtractorUtils:

https://github.com/facebook/litho/blob/ce87d198c8f5ac0cee2c9302cb48076b06253ef6/litho-processor/src/main/java/com/facebook/litho/specmodels/processor/MethodExtractorUtils.java#L99

That field is an internal implementation detail of javac and is not part of the supported API. It is being removed in JDK 10. See this change: http://hg.openjdk.java.net/jdk/jdk/rev/89f6aa26fd6c, which fixes JDK-8177486 and JDK-8007720.

The removal of the field causes DelegateMethodExtractor to crash when running on a JDK 10 javac:

Caused by: java.lang.NoSuchFieldError: savedParameterNames
    at com.facebook.litho.specmodels.processor.MethodExtractorUtils.getSavedParameterNames(MethodExtractorUtils.java:87)
    at com.facebook.litho.specmodels.processor.MethodExtractorUtils.getMethodParams(MethodExtractorUtils.java:45)
    at com.facebook.litho.specmodels.processor.DelegateMethodExtractor.getDelegateMethods(DelegateMethodExtractor.java:63)
    at com.facebook.litho.specmodels.processor.LayoutSpecModelFactory.create(LayoutSpecModelFactory.java:79)
    at com.facebook.litho.specmodels.processor.LayoutSpecModelFactory.create(LayoutSpecModelFactory.java:33)
    at com.facebook.litho.specmodels.processor.AbstractComponentsProcessor.process(AbstractComponentsProcessor.java:66)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:969)

Most helpful comment

Thanks - that achieves binary compatibility with JDK 10, but not source compatibility. WDYT about Symbol.MethodSymbol.class.getField("savedParameterNames").get(methodSymbol)?

All 9 comments

@cushon are we sure that this is something that works? Can you please share some info on how you tested it? Seems to me that at least a previous existing functionality looks broken on a quick look at the code diff, especially at the line http://hg.openjdk.java.net/jdk/jdk/rev/89f6aa26fd6c#l1.36 (the i is not being incremented properly like it was before). Also is this something final that will end up on JDK 10?

@pavlospt thanks for catching that. As I mentioned in the compiler-dev thread I think the patch is OK, and the index that isn't incremented is effectively dead code.

For JDK 10 it should be sufficient to compile with -parameters and then use the names on the symbols returned by getParameters(). With JDK 8 and 9 some of the litho tests were running into JDK-8007720 - normally savedParameterNames should be null by the time annotation processing happens.

@cushon thanks for the follow up :)

Hey @cushon! Thanks for reporting this. I'm kinda jealous of you for tracking the JDK so closely. We have to maintain compatibility with JDK 7, which means we make use of -parameters yet.

Because of the limitation stated in the patch description itself, I had to implement a workaround for this anyway. We are now persisting parameter names in META-INF as resources during codegen, which should make this entire fallback unnecessary. The only place where this might still be used is in tests.

I'll see if I can remove it altogether and if not, I will wrap this in a try/catch to make sure this doesn't break with JDK 10.

I went with a try/catch to maintain backwards compatibility. I hope this works for you!

Thanks - that achieves binary compatibility with JDK 10, but not source compatibility. WDYT about Symbol.MethodSymbol.class.getField("savedParameterNames").get(methodSymbol)?

Sounds good to me. Thanks, I'll make that change!

friendly bump :) will help clean up my import script to have source compatibility here before the next release

Thanks for the reminder. I'll make that change tomorrow!

On Wed, 10 Jan 2018, 21:00 Vince Mi, notifications@github.com wrote:

friendly bump :) will help clean up my import script to have source
compatibility here before the next release

—
You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
https://github.com/facebook/litho/issues/295#issuecomment-356734997, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAmshatLeWBUptiK8_DI-rnO3id0Zntks5tJSTUgaJpZM4RN5sq
.

>

timezone: eu/london | utc+1
@passy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Syne10 picture Syne10  Â·  6Comments

Martin-Hogge picture Martin-Hogge  Â·  4Comments

tpucci picture tpucci  Â·  4Comments

ersin-ertan picture ersin-ertan  Â·  7Comments

doublechina picture doublechina  Â·  3Comments