我在使用proguard-maven-plugin(github.com/wvengen/proguard-maven-plugin)时遇到ProGuard 4.11(可以优化,缩小和混淆Java代码的应用程序)的问题(尽管这不重要)那么多,因为错误是在运行时发生的,并且maven插件只是用我知道的一些参数调用二进制文件).
我有一个注释类,它被这样结构化(没什么特别的):
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD)
public @interface SqlValueCache {
String value();
SqlValueCache.Type type() default Type.OBJECT_UPDATE; //Type is just an ordinary enum
}
Run Code Online (Sandbox Code Playgroud)
我也有一些使用该注释注释的字段,但我正在跳过type()参数,因为我想使用默认值:
@SqlValueCache("nickname")
protected SqlValueHolder<String> nick;
Run Code Online (Sandbox Code Playgroud)
现在我想在运行时处理该注释:
SqlValueCache annotation = field.getAnnotation(SqlValueCache.class); //Skipped the validation
annotation.value(); //Works fine, because specified
annotation.type(); //java.lang.annotation.IncompleteAnnotationException, *not* using the default
Run Code Online (Sandbox Code Playgroud)
如上面的评论所述,我得到一个IncompleteAnnotationException,说明我的注释声明缺少type()值.但是这个价值应该被暗示default Type.OBJECT_UPDATE!所以现在我想知道,为什么会这样?
我假设default的东西储存在某种属性,我需要指定的-keepattributes,但我一直无法弄清楚,如果这是真的还是哪一个是.
不使用ProGuard时,它确实可以正常工作.
我还确保问题实际上是缺少的隐含值 - 代码在使用ProGuard时按预期运行,但明确指定了type(),如下所示:
@SqlValueCache(value = "nickname", type = Type.OBJECT_UPDATE) …Run Code Online (Sandbox Code Playgroud)