简体   繁体   English

PMD eclipse 插件中的误报

[英]False positives in PMD eclipse plugin

Eclipse 2019-09, Java 11.0.5, PMD plugin 4.8.0 Eclipse 2019-09,Java 11.0.5,PMD插件4.8.0

@Test
public final void testValueOf() {
    final String message = "Colour Object correctly set?";
    assertEquals(diamond, QCardColour.valueOf('d'), message);
    assertEquals(heart, QCardColour.valueOf('h'), message);
    assertEquals(spade, QCardColour.valueOf('s'), message);
    assertEquals(club, QCardColour.valueOf('c'), message);
    assertThrows(IllegalArgumentException.class, () -> {
        QCardColour.valueOf('B');
    }, message);
}

PMD eclipse plugin marks the assertEquals with JUnit assertions should include a message which obviously is wrong. PMD eclipse 插件将 assertEquals 标记为JUnit assertions should include a message Gradle pmd plugin, working with the same ruleset.xml, shows no errors. Gradle pmd 插件,使用相同的规则集。xml,显示没有错误。 How do i get rid of those messages without deactivating the rule?如何在不停用规则的情况下摆脱这些消息?

Edit: The error shows up only in one project.编辑:错误只出现在一个项目中。 In at least two other projects where assertEquals is in use, everything is fine.在至少另外两个使用 assertEquals 的项目中,一切都很好。

This sounds like PMD issue 1009 which has been fixed some time ago.这听起来像是前一段时间已修复的PMD 问题 1009 PMD 6.19.0 should contain this fix. PMD 6.19.0 应该包含此修复程序。 The fix makes the rule less strict to handle both, JUnit 4 (where in assertEquals the message is the first parameter) and JUnit 5 (message is the third parameter).该修复使规则对处理 JUnit 4 (其中assertEquals中的消息是第一个参数)和 JUnit 5 (消息是第三个参数)的规则不那么严格。

It's unclear why you're running into this issue with the pmd-eclipse-plugin 4.8.0 as it should contain PMD 6.19.0 with the fix for JUnit 5. You might report the issue to the pmd-eclipse-plugin team .目前尚不清楚为什么您在使用 pmd-eclipse-plugin 4.8.0 时遇到此问题,因为它应该包含PMD 6.19.0并修复了 JUnit 5。您可以将问题报告给 pmd-eclipse-plugin 团队 There is more than one Eclipse PMD plug-in that you might use, at least until the issue is fixed.至少在问题得到解决之前,您可能会使用多个 Eclipse PMD 插件

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

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