简体   繁体   English

如何解决STS中的PMD问题

[英]How to resolve PMD issue in STS

AppCommonUtils.optional(customerVO.getPincode()).map(Integer::valueOf).map(mstPincodeCityRepository::findCityByPincode).ifPresent(mstPincode -> {
    mstAddress.setPincode(customerVO.getPincode());
    mstAddress.setMstCity(mstPincode.getMstCity());
});

For above code PMD showing :: Potential violation of Law of Demeter (method chain calls) 对于上面的代码PMD,显示::可能违反了Demeter定律(方法链调用)

Can someone please suggest how to remove this warning PMD message? 有人可以建议如何删除此PMD警告消息吗?

The problem relies on AppCommonUtils.optional . 该问题取决于AppCommonUtils.optional That method is returning an object you didn't create directly, and are then manipulating, which is a violation for this rule. 该方法将返回您未直接创建的对象,然后进行操作,这违反了该规则。

See: https://pmd.github.io/pmd-6.10.0/pmd_rules_java_design.html#lawofdemeter 参见: https : //pmd.github.io/pmd-6.10.0/pmd_rules_java_design.html#lawofdemeter

As that is a factory method, this behavior is by design and not a problem. 因为这是工厂方法,所以这种行为是设计使然,而不是问题。 I'd suggest you simply suppress it 我建议你简单地压制它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM