rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
607 stars 103 forks source link

NullPointerException processing ImmutableList.Builder Builder method #264

Open chris9871 opened 3 years ago

chris9871 commented 3 years ago

Sample class:

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

@AutoValue
abstract class MyAv2 {
    public abstract ImmutableList<String> items();

    public static Builder builder() {
        return new AutoValue_MyAv2.Builder();
    }

    @AutoValue.Builder
    public abstract static class Builder {
        public abstract ImmutableList.Builder<String> itemsBuilder();

        public Builder addItem(final String item) {
            itemsBuilder().add(item);
            return this;
        }

        public abstract MyAv2 build();
    }

    public static TypeAdapter<MyAv2> typeAdapter(Gson gson) {
        return new AutoValue_MyAv2.GsonTypeAdapter(gson);
    }
}

Exception shape:

BUILD:128:13: Building projects/services/disco/zoobernetes/libbase_lib-class.jar (30 source files) and running annotation processors (AutoValueProcessor, AutoValueGsonAdapterFactoryProcessor) failed (Exit 1): java failed: error executing command tools/jdk/Darwin/openjdk_11.0.10_11.45.28_x64/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' ... (remaining 15 argument(s) skipped)
MyAv2.java:9: error: [AutoValueException] @AutoValue processor threw an exception: java.lang.NullPointerException
abstract class MyAv2 {
         ^
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.addBuilderFieldSetting(AutoValueGsonExtension.java:559)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.createReadMethod(AutoValueGsonExtension.java:821)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.createTypeAdapter(AutoValueGsonExtension.java:513)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.generateClass(AutoValueGsonExtension.java:286)
    at com.google.auto.value.processor.AutoValueProcessor.writeExtensions(AutoValueProcessor.java:301)
    at com.google.auto.value.processor.AutoValueProcessor.processType(AutoValueProcessor.java:263)
    at com.google.auto.value.processor.AutoValueishProcessor.process(AutoValueishProcessor.java:350)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:972)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:888)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1214)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1326)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
    at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:117)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.fallback(ReducedClasspathJavaLibraryBuilder.java:103)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:65)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:108)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:115)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:81)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:61)
    at com.google.devtools.build.buildjar.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:99)
    at com.google.devtools.build.buildjar.WorkRequestHandler.lambda$createResponseThread$0(WorkRequestHandler.java:82)
    at java.base/java.lang.Thread.run(Thread.java:834)
java.lang.RuntimeException: java.lang.NullPointerException
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:163)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
    at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:117)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.fallback(ReducedClasspathJavaLibraryBuilder.java:103)
    at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:65)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:108)
    at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:115)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.build(BazelJavaBuilder.java:81)
    at com.google.devtools.build.buildjar.BazelJavaBuilder.parseAndBuild(BazelJavaBuilder.java:61)
    at com.google.devtools.build.buildjar.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:99)
    at com.google.devtools.build.buildjar.WorkRequestHandler.lambda$createResponseThread$0(WorkRequestHandler.java:82)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.addBuilderFieldSetting(AutoValueGsonExtension.java:559)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.createReadMethod(AutoValueGsonExtension.java:821)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.createTypeAdapter(AutoValueGsonExtension.java:513)
    at com.ryanharter.auto.value.gson.AutoValueGsonExtension.generateClass(AutoValueGsonExtension.java:286)
    at com.google.auto.value.processor.AutoValueProcessor.writeExtensions(AutoValueProcessor.java:301)
    at com.google.auto.value.processor.AutoValueProcessor.processType(AutoValueProcessor.java:263)
    at com.google.auto.value.processor.AutoValueishProcessor.process(AutoValueishProcessor.java:350)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:972)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:888)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1214)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1326)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
    at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
    ... 12 more
INFO: Elapsed time: 1.884s, Critical Path: 1.52s

This appears to fail in 1.3.0+ and works in 1.0.0.