protoc-jar-maven-plugin icon indicating copy to clipboard operation
protoc-jar-maven-plugin copied to clipboard

NPE while executing plugin on unchanged proto files

Open vicmosin opened this issue 3 years ago • 4 comments

  1. mvn clean
  2. mvn generate-sources -> generates initially
  3. mvn generate-sources -> fails with
Caused by: java.lang.NullPointerException: Cannot read the array length because "<local6>" is null
    at com.github.os72.protocjar.Protoc.extractStdTypes (Protoc.java:372)
    at com.github.os72.protocjar.maven.ProtocJarMojo.performProtoCompilation (ProtocJarMojo.java:397)
    at com.github.os72.protocjar.maven.ProtocJarMojo.execute (ProtocJarMojo.java:370)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

Config to reproduce:

         <plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.11.4</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <protocArtifact>com.google.protobuf:protoc:3.12.0</protocArtifact>
                            <includeStdTypes>true</includeStdTypes>
                            <inputDirectories>
                                <include>../proto</include>
                            </inputDirectories>
                            <outputTargets>
                                <outputTarget>
                                    <type>java</type>
                                </outputTarget>
                                <outputTarget>
                                    <type>grpc-java</type>
                                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}</pluginArtifact>
                                </outputTarget>
                            </outputTargets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I assume that happens only when optimizeCodegen=true, setting it to false works (at least as workaround)

vicmosin avatar May 12 '21 13:05 vicmosin

Is there any progress on this issue?

Yes, optimizeCodegen=true seems to be a workaround, but I don't think it should be accepted as a solution.

serdaryesilmurat avatar Nov 30 '21 05:11 serdaryesilmurat

Not sure it'll move forward without some support for the project

os72 avatar Dec 05 '21 01:12 os72

hi, im facing the same error.... some solutions? or where do you put optimizeCodegen=true option?

Qleoz12 avatar Jan 20 '23 23:01 Qleoz12

This is #121, #60, #117.

The error manifests because of an interplay between <includeStdTypes>, <protocArtifact>, and <protocVersion>.

  1. <includeStdTypes> triggers a protocol major version lookup
  2. but that lookup only succeeds if <protocVersion> is set and otherwise sets local6=null
  3. but <protocArtifact> usually takes the place of <protocVersion> because of #139 (#61).

Fortunately <protocArtifact> supersedes <protocVersion> for protoc resolution so all three settings can be safely specified.

Alternatively, it may be that <includeMavenTypes> can safely and adequately substitute <includeStdTypes> and thereby obviate <protocVersion>. I have not tried this.

commonquail avatar Feb 09 '24 16:02 commonquail