@SuppressWarnings more than one rule not working

♀尐吖头ヾ 提交于 2019-12-23 10:14:16

问题


PMD and SonarQube a nice tools but I have problems trying to suppress PMD warnings.

We use Lombok a lot in our project, so many of the model classes have a: @SuppressWarnings("PMD.UnusedPrivateField") as an class-level annotations.

This works fine.

The problem is, that if I wan't to ignore one more rule, I would expect the following syntax: @SuppressWarnings(value = { "PMD.UnusedPrivateField", "PMD.SingularField" }) This looks like the correct syntax, also reading the implementation of the PMD annotation.

However, this seems not to works: None of the rules are now suppressed.


回答1:


I would have expected this format (without the "value ="):

@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})

Similar format is working for me in PMD 5.1.3 (although Eclipse complains about them not being supported).




回答2:


As @colbadhombre writes:

@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})

does the trick.

Regarding Eclipse:
Open Window->Preferences->Java->Compiler->Errors/Warnings

  • "Unhandled token in '@SuppressWarnings':" can be set to Ignore
  • Likewise the "Unused '@SuppressWarnings' token" if the warnings are enabled


来源:https://stackoverflow.com/questions/22855796/suppresswarnings-more-than-one-rule-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!