jhunters / jprotobuf

A useful utility library for java programmer using google protobuf
Apache License 2.0
897 stars 283 forks source link

预编译插件在复杂对象中可能编译出错 #206

Open LinHuiG opened 10 months ago

LinHuiG commented 10 months ago

我声明了TestSe1,TestSe2,TestSe3三个类,并使用@ProtobufClass@Protobuf注解它们,在TestSe2中引用了TestSe1TestSe3

@ProtobufClass
public class TestSe2 {
    @Protobuf
    List<TestSe1> testSe1List;
    @Protobuf
    TestSe3 testSe3List;
}

这时候使用预编译插件会出现如下报错,经过测试发现当我把TestSe3改名为'TestSe0'后,编译正常。 有如下规律:

  1. 当我的复杂类的成员变量的类都被编译后,再编译复杂类则正常
  2. 若先编译复杂对象,则未编译的成员变量的类无法通过编译,注:可通过改类名的方式调整编译顺序。
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at com.baidu.jprotobuf.mojo.PreCompileMojo$1.run (PreCompileMojo.java:326)
    at java.lang.Thread.run (Thread.java:748)
    Caused by: jodd.io.findfile.FindFileException: Scan entry error: EntryData{learning.se.TestSe3'}; <--- java.lang.NullPointerException
    at jodd.io.findfile.ClassFinder.scanEntry (ClassFinder.java:377)
    at jodd.io.findfile.ClassFinder.scanClassFile (ClassFinder.java:324)
    at jodd.io.findfile.ClassFinder.scanClassPath (ClassFinder.java:307)
    at jodd.io.findfile.ClassFinder.scanPath (ClassFinder.java:239)
    at jodd.io.findfile.ClassFinder.scanPaths (ClassFinder.java:178)
    at jodd.io.findfile.ClassScanner.scan (ClassScanner.java:35)
    at jodd.io.findfile.ClassScanner.scanDefaultClasspath (ClassScanner.java:28)
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain.main (JprotobufPreCompileMain.java:182)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at com.baidu.jprotobuf.mojo.PreCompileMojo$1.run (PreCompileMojo.java:326)
    at java.lang.Thread.run (Thread.java:748)
    Caused by: java.lang.Exception
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain$1.onEntry (JprotobufPreCompileMain.java:144)
    at jodd.io.findfile.ClassFinder.scanEntry (ClassFinder.java:375)
    at jodd.io.findfile.ClassFinder.scanClassFile (ClassFinder.java:324)
    at jodd.io.findfile.ClassFinder.scanClassPath (ClassFinder.java:307)
    at jodd.io.findfile.ClassFinder.scanPath (ClassFinder.java:239)
    at jodd.io.findfile.ClassFinder.scanPaths (ClassFinder.java:178)
    at jodd.io.findfile.ClassScanner.scan (ClassScanner.java:35)
    at jodd.io.findfile.ClassScanner.scanDefaultClasspath (ClassScanner.java:28)
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain.main (JprotobufPreCompileMain.java:182)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at com.baidu.jprotobuf.mojo.PreCompileMojo$1.run (PreCompileMojo.java:326)
    at java.lang.Thread.run (Thread.java:748)
    Caused by: java.lang.NullPointerException
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain.createProtoFile (JprotobufPreCompileMain.java:255)
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain.access$5 (JprotobufPreCompileMain.java:238)
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain$1.onEntry (JprotobufPreCompileMain.java:136)
    at jodd.io.findfile.ClassFinder.scanEntry (ClassFinder.java:375)
    at jodd.io.findfile.ClassFinder.scanClassFile (ClassFinder.java:324)
    at jodd.io.findfile.ClassFinder.scanClassPath (ClassFinder.java:307)
    at jodd.io.findfile.ClassFinder.scanPath (ClassFinder.java:239)
    at jodd.io.findfile.ClassFinder.scanPaths (ClassFinder.java:178)
    at jodd.io.findfile.ClassScanner.scan (ClassScanner.java:35)
    at jodd.io.findfile.ClassScanner.scanDefaultClasspath (ClassScanner.java:28)
    at com.baidu.jprotobuf.mojo.JprotobufPreCompileMain.main (JprotobufPreCompileMain.java:182)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at com.baidu.jprotobuf.mojo.PreCompileMojo$1.run (PreCompileMojo.java:326)
    at java.lang.Thread.run (Thread.java:748)
LinHuiG commented 10 months ago

jdk版本是oracle jdk 1.8.201

linpeilie commented 10 months ago

同样存在该问题。 v2.2.9

jhunters commented 10 months ago

TestSe3 类的定义能否发一下, 我复现一下看看

jhunters commented 10 months ago

关于编译依赖,代码是有实现依赖分析的,你这种场景看看是不是有特殊的路径没有被覆盖到

linpeilie commented 10 months ago

https://github.com/linpeilie/tutelary 这个项目中有引用,可以修改父 pom 中的 jprotobuf-precompile.version 为2.2.9,对 tutelary-message clean compile 就会抛出这个异常。现在用的 2.2.8 不会

Aliang-code commented 9 months ago

2.2.9同复现

LinHuiG commented 8 months ago

TestSe3 类的定义能否发一下, 我复现一下看看

@ProtobufClass public class TestSe3 { @Protobuf int a; }

@ProtobufClass public class TestSe1 { @Protobuf public int a; @Protobuf public long b; @Protobuf public double c; @Protobuf public boolean d; @Protobuf public String e; @Protobuf public String f; } 这里面没有使用什么特殊的定义