java-如何阻止 lombok 在 Eclipse 中将注释复制到 getter/setter?
我们在运行 Lombok > 1.18.18 作为 Eclipse 代理(2022-06 或 v4.24.0)时遇到问题......它开始将 JSR-303 Bean Validation 约束复制到生成的设置器。我们很惊讶,因为这不向后兼容。注释以前未注释的函数绝对是一个重大变化:/
这会混淆 Apache BVal 实现(v2.0.5),因为通常您不会同时注释字段和设置器。我实际上不知道 jsr303 规范是否允许这样做,但我的猜测是它是无效的,因为它不遵循 DRY 原则。
有一个配置键lombok.copyableAnnotations来控制行为,但我们似乎无法让 Eclipse/Lombok 关心它。我们在项目根目录中放置了一个 lombok.config,内容如下:
config.stopBubbling = true
lombok.copyableAnnotations =
确实如此还复制注释:
public void setUserName(java.lang.String);
descriptor: (Ljava/lang/String;)V
flags: (0x0001) ACC_PUBLIC
RuntimeVisibleParameterAnnotations:
parameter 0:
0: #26()
javax.validation.constraints.NotNull
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: aload_1
2: putfield #66 // Field userName:Ljava/lang/String;
5: return
LineNumberTable:
line 43: 0
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this Lcom/xxx/xxx/xxx/xxx/xxx/xxx/LoginPage;
0 6 1 userName Ljava/lang/String;
RuntimeVisibleTypeAnnotations:
0: #26(): METHOD_FORMAL_PARAMETER, param_index=0
javax.validation.constraints.NotNull
MethodParameters:
Name Flags
userName final
任何防止这种情况的帮助将不胜感激!谢谢!
编辑
原始堆栈跟踪:
Caused by: java.lang.ClassCastException: class org.apache.bval.jsr.descriptor.ComposedD$ForProperty cannot be cast to class org.apache.bval.jsr.descriptor.ElementD (org.apache.bval.jsr.descriptor.ComposedD$ForProperty and org.apache.bval.jsr.descriptor.ElementD are in unnamed module of loader java.net.URLClassLoader @1fbc7afb)
at org.apache.bval.jsr.job.ValidateProperty$DescriptorWrapper.<init>(ValidateProperty.java:159)
at org.apache.bval.jsr.job.ValidateProperty$FindDescriptor.handleProperty(ValidateProperty.java:219)
at org.apache.bval.jsr.job.ValidateProperty$WalkGraph.handleProperty(ValidateProperty.java:312)
at org.apache.bval.jsr.util.PathNavigation$PathPosition.handleProperty(PathNavigation.java:324)
at org.apache.bval.jsr.util.PathNavigation.parse(PathNavigation.java:218)
at org.apache.bval.jsr.util.PathNavigation.navigateAndReturn(PathNavigation.java:176)
... 86 more