diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 197b7a4aec..16315bf5b2 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -17,15 +17,16 @@ This is a {{ site.pmd.release_type }} release.
### 🌟 Rule Changes
#### Renamed Rules
-Several rules for unit testing have been renamed to better reflect their actual scope. Lots of them were called
-after JUnit / JUnit 4, even when they applied to JUnit 5 and / or TestNG.
-
-* {% rule java/bestpractices/UnitTestAssertionsShouldIncludeMessage %} (Java Best Practices) has been renamed from `JUnitAssertionsShouldIncludeMessage`.
-* {% rule java/bestpractices/UnitTestContainsTooManyAsserts %} (Java Best Practices) has been renamed from `JUnitTestContainsTooManyAsserts`.
-* {% rule java/bestpractices/UnitTestShouldIncludeAssert %} (Java Best Practices) has been renamed from `JUnitTestsShouldIncludeAssert`.
-* {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseAfterAnnotation`.
-* {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseBeforeAnnotation`.
-* {% rule java/bestpractices/UnitTestShouldUseTestAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseTestAnnotation`.
+* Several rules for unit testing have been renamed to better reflect their actual scope. Lots of them were called
+ after JUnit / JUnit 4, even when they applied to JUnit 5 and / or TestNG.
+ * {% rule java/bestpractices/UnitTestAssertionsShouldIncludeMessage %} (Java Best Practices) has been renamed from `JUnitAssertionsShouldIncludeMessage`.
+ * {% rule java/bestpractices/UnitTestContainsTooManyAsserts %} (Java Best Practices) has been renamed from `JUnitTestContainsTooManyAsserts`.
+ * {% rule java/bestpractices/UnitTestShouldIncludeAssert %} (Java Best Practices) has been renamed from `JUnitTestsShouldIncludeAssert`.
+ * {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseAfterAnnotation`.
+ * {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseBeforeAnnotation`.
+ * {% rule java/bestpractices/UnitTestShouldUseTestAnnotation %} (Java Best Practices) has been renamed from `JUnit4TestShouldUseTestAnnotation`.
+* {% rule java/errorprone/NonCaseLabelInSwitch %} (Java Error Prone) has been renamed from `NonCaseLabelInSwitchStatement` as it also applies
+ to Switch Expressions.
The old rule names still work but are deprecated.
@@ -43,7 +44,8 @@ The old rule names still work but are deprecated.
* The old rule name `JUnitAssertionsShouldIncludeMessage` has been deprecated. Use the new name {% rule java/bestpractices/UnitTestAssertionsShouldIncludeMessage %} instead.
* The old rule name `JUnitTestContainsTooManyAsserts` has been deprecated. Use the new name {% rule java/bestpractices/UnitTestContainsTooManyAsserts %} instead.
* The old rule name `JUnitTestsShouldIncludeAssert` has been deprecated. Use the new name {% rule java/bestpractices/UnitTestShouldIncludeAssert %} instead.
-
+* java-errorprone
+ * The old rule name `NonCaseLabelInSwitchStatement` has been deprecated. Use the new name {% rule java/errorprone/NonCaseLabelInSwitch %} instead.
### ✨ Merged pull requests
* [#4965](https://github.com/pmd/pmd/pull/4965): \[java] Rename JUnit rules with overly restrictive names - [Juan MartÃn Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod)
diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml
index 1f9ed37765..875c5d8157 100644
--- a/pmd-java/src/main/resources/category/java/errorprone.xml
+++ b/pmd-java/src/main/resources/category/java/errorprone.xml
@@ -2185,20 +2185,24 @@ public class Foo {
-
+
+
-A non-case label (e.g. a named break/continue label) was present in a switch statement.
+A non-case label (e.g. a named break/continue label) was present in a switch statement or switch expression.
This is legal, but confusing. It is easy to mix up the case labels and the non-case labels.
+
+Note: This rule was renamed from `NonCaseLabelInSwitchStatement` with PMD 7.7.0.
3
- //SwitchStatement//LabeledStatement
+ //(SwitchStatement|SwitchExpression)//LabeledStatement
@@ -2208,7 +2212,6 @@ public class Foo {
switch (a) {
case 1:
// do something
- break;
mylabel: // this is legal, but confusing!
break;
default:
diff --git a/pmd-java/src/main/resources/rulesets/java/quickstart.xml b/pmd-java/src/main/resources/rulesets/java/quickstart.xml
index 3ac03a493c..3f8b129015 100644
--- a/pmd-java/src/main/resources/rulesets/java/quickstart.xml
+++ b/pmd-java/src/main/resources/rulesets/java/quickstart.xml
@@ -243,7 +243,7 @@
-
+
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchStatementTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchTest.java
similarity index 78%
rename from pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchStatementTest.java
rename to pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchTest.java
index 9d914a9552..8644b8d91c 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchStatementTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/errorprone/NonCaseLabelInSwitchTest.java
@@ -6,6 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.errorprone;
import net.sourceforge.pmd.test.PmdRuleTst;
-class NonCaseLabelInSwitchStatementTest extends PmdRuleTst {
+class NonCaseLabelInSwitchTest extends PmdRuleTst {
// no additional unit tests
}
diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitch.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitch.xml
new file mode 100644
index 0000000000..d40af2f6c9
--- /dev/null
+++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitch.xml
@@ -0,0 +1,155 @@
+
+
+
+
+ label inside switch statement, not ok
+ 1
+ 5
+
+
+
+
+ label inside switch expression, not ok
+ 1
+ 5
+
+
+
+
+ only cases in switch statement, ok
+ 0
+
+
+
+
+ only cases in switch expression, ok
+ 0
+
+
+
+
+ label in switch statement with arrow syntax, not ok
+ 1
+ 6
+ {
+ int y=8;
+ somelabel:
+ break;
+ }
+ default -> {
+ int j=8;
+ }
+ }
+ }
+}
+]]>
+
+
+
+ label in switch expression with arrow syntax, not ok
+ 1
+ 5
+ { int y=8;
+ somelabel:
+ yield y;
+ }
+ default -> {
+ int j=8;
+ yield j;
+ }
+ };
+ }
+}
+]]>
+
+
+
+ only cases in switch stmt/expr with arrow syntax, ok
+ 0
+ {
+ int y=8;
+ break;
+ }
+ default -> {
+ int j=8;
+ }
+ }
+ }
+ void barArrow(int x) {
+ x = switch (x) {
+ case 2 -> { int y=8;
+ yield y;
+ }
+ default -> {
+ int j=8;
+ yield j;
+ }
+ };
+ }
+}
+]]>
+
+
diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitchStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitchStatement.xml
deleted file mode 100644
index b2ba4cecd0..0000000000
--- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonCaseLabelInSwitchStatement.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
- label inside switch
- 1
- 6
-
-
-
-
- ok
- 0
-
-
-