From 40492c79cdd9ebc60d9b6a72c32e3acb10bc00c2 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Fri, 28 Nov 2025 15:48:37 +0100 Subject: [PATCH 1/9] Bump minimum JDK version to Java 21 --- README.md | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d86e7504..72041975 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ It provides all necessary resources for a Java project to enforce this coding st - [SpotBugs](https://spotbugs.github.io) - [Error Prone](https://errorprone.info) -❗This project requires a JDK version of 17 or higher.❗ +❗This project requires a JDK version of 21 or higher.❗ Moreover, this project provides some sample classes that already use this style guide. These classes can be used as such but are not required in this project. @@ -54,4 +54,4 @@ Source code (snippets, examples, and classes) are using the [MIT license](https: [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://en.wikipedia.org/wiki/MIT_License) [![License: CC BY 4.0](https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/) -![JDK17](https://img.shields.io/badge/jdk-17-blue.svg) +![JDK21](https://img.shields.io/badge/jdk-21-blue.svg) diff --git a/pom.xml b/pom.xml index 5c095b67..abc7312d 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ UTF-8 ${source.encoding} - 17 + 21 21 ${project.groupId}.codingstyle @@ -361,7 +361,7 @@ org.openrewrite.staticanalysis.CodeCleanup org.openrewrite.staticanalysis.CommonStaticAnalysis org.openrewrite.staticanalysis.RemoveExtraSemicolons - org.openrewrite.java.migrate.UpgradeToJava17 + org.openrewrite.java.migrate.UpgradeToJava21 org.openrewrite.java.migrate.util.SequencedCollection org.openrewrite.java.migrate.lang.var.UseVarForObject org.openrewrite.java.migrate.net.JavaNetAPIs From 58d6e9f411e93eb06ad363654ebbe50fe078635f Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Mon, 1 Dec 2025 11:27:28 +0100 Subject: [PATCH 2/9] Run OpenRewrite Java 21 migration --- src/test/java/edu/hm/hafner/util/EnsureTest.java | 6 +++--- .../java/edu/hm/hafner/util/LineRangeListTest.java | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/edu/hm/hafner/util/EnsureTest.java b/src/test/java/edu/hm/hafner/util/EnsureTest.java index fa3b659b..2565be6d 100644 --- a/src/test/java/edu/hm/hafner/util/EnsureTest.java +++ b/src/test/java/edu/hm/hafner/util/EnsureTest.java @@ -29,7 +29,7 @@ void shouldNotThrowExceptionIfContractIsValid() { Ensure.that("").isNotNull(); Ensure.that("", "").isNotNull(); Ensure.that(null, (Object) null).isNull(); - Ensure.that(new String[] {""}).isNotEmpty(); + Ensure.that(new String[]{""}).isNotEmpty(); Ensure.that(SOME_STRING).isNotEmpty(); Ensure.that(SOME_STRING).isNotBlank(); Ensure.that("").isInstanceOf(String.class); @@ -116,7 +116,7 @@ void shouldThrowExceptionIfEmpty() { Ensure.that(Lists.newArrayList("", null, "")).isNotEmpty(ERROR_MESSAGE)).isInstanceOf( AssertionError.class); assertThatThrownBy(() -> - Ensure.that(new String[] {"", null, ""}).isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); + Ensure.that(new String[]{"", null, ""}).isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> Ensure.that("").isNotEmpty(ERROR_MESSAGE)).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> @@ -128,7 +128,7 @@ void shouldThrowExceptionIfEmpty() { assertThatThrownBy(() -> Ensure.that(Lists.newArrayList("", null, "")).isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> - Ensure.that(new String[] {"", null, ""}).isNotEmpty()).isInstanceOf(AssertionError.class); + Ensure.that(new String[]{"", null, ""}).isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> Ensure.that("").isNotEmpty()).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> diff --git a/src/test/java/edu/hm/hafner/util/LineRangeListTest.java b/src/test/java/edu/hm/hafner/util/LineRangeListTest.java index 4c4ffb32..2257f5ac 100644 --- a/src/test/java/edu/hm/hafner/util/LineRangeListTest.java +++ b/src/test/java/edu/hm/hafner/util/LineRangeListTest.java @@ -1,9 +1,9 @@ package edu.hm.hafner.util; -import java.util.List; - import org.junit.jupiter.api.Test; +import java.util.List; + import static org.assertj.core.api.Assertions.*; /** @@ -43,17 +43,17 @@ void shouldSupportSetOperations() { var range = new LineRange(1, 2); list.add(range); - assertThat(list.get(0)).isEqualTo(range); - assertThat(list.get(0)).isNotSameAs(range); + assertThat(list.getFirst()).isEqualTo(range); + assertThat(list.getFirst()).isNotSameAs(range); assertThat(list).hasSize(1); var other = new LineRange(3, 4); assertThat(list.set(0, other)).isEqualTo(range); - assertThat(list.get(0)).isEqualTo(other); - assertThat(list.get(0)).isNotSameAs(other); + assertThat(list.getFirst()).isEqualTo(other); + assertThat(list.getFirst()).isNotSameAs(other); assertThat(list).hasSize(1); - assertThat(list.remove(0)).isEqualTo(other); + assertThat(list.removeFirst()).isEqualTo(other); assertThat(list).hasSize(0); } From 51e1da7364b6b4112b283ccdaa51cf1dc1cc2753 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Mon, 1 Dec 2025 17:21:26 +0100 Subject: [PATCH 3/9] Improve documentation --- src/main/java/edu/hm/hafner/util/FilteredLog.java | 8 ++++---- src/main/java/edu/hm/hafner/util/Generated.java | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/hm/hafner/util/FilteredLog.java b/src/main/java/edu/hm/hafner/util/FilteredLog.java index f3e730bc..6e3d896d 100644 --- a/src/main/java/edu/hm/hafner/util/FilteredLog.java +++ b/src/main/java/edu/hm/hafner/util/FilteredLog.java @@ -31,10 +31,10 @@ public class FilteredLog implements Serializable { private final int maxLines; private int lines; - @SuppressWarnings("serial") - private final List infoMessages = new ArrayList<>(); - @SuppressWarnings("serial") - private final List errorMessages = new ArrayList<>(); + @SuppressWarnings("PMD.LooseCoupling") + private final ArrayList infoMessages = new ArrayList<>(); + @SuppressWarnings("PMD.LooseCoupling") + private final ArrayList errorMessages = new ArrayList<>(); private transient ReentrantLock lock = new ReentrantLock(); diff --git a/src/main/java/edu/hm/hafner/util/Generated.java b/src/main/java/edu/hm/hafner/util/Generated.java index 9073ba0b..4f7122f6 100644 --- a/src/main/java/edu/hm/hafner/util/Generated.java +++ b/src/main/java/edu/hm/hafner/util/Generated.java @@ -8,13 +8,11 @@ /** * This annotation is used to mark source code that has been generated or is somehow not relevant for style checking or - * code coverage analysis. It is quite similar to the JSR305 annotation. The - * main difference is that it has class retention, so it is available for tools that work on bytecode (like JaCoCo, - * PIT, or SpotBugs). + * code coverage analysis. It is quite similar to the annotation of the abandoned JSR305 project. The main difference is + * that it has class retention, so it is available for tools that work on bytecode (like JaCoCo, PIT, or SpotBugs). */ @Retention(CLASS) -@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, - LOCAL_VARIABLE, PARAMETER}) +@Target({PACKAGE, TYPE, ANNOTATION_TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE, PARAMETER}) public @interface Generated { /** * An optional property that identifies the code generator. From 42fe256b8f8689d347b031d0923e4d693e997d71 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Fri, 19 Dec 2025 12:57:42 +0100 Subject: [PATCH 4/9] Increase serialization version ID --- src/main/java/edu/hm/hafner/util/FilteredLog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/hm/hafner/util/FilteredLog.java b/src/main/java/edu/hm/hafner/util/FilteredLog.java index 6e3d896d..e446025d 100644 --- a/src/main/java/edu/hm/hafner/util/FilteredLog.java +++ b/src/main/java/edu/hm/hafner/util/FilteredLog.java @@ -23,7 +23,7 @@ */ public class FilteredLog implements Serializable { @Serial - private static final long serialVersionUID = -8552323621953159904L; + private static final long serialVersionUID = 6956036398485594488L; private static final int DEFAULT_MAX_LINES = 20; From 715e38d533bbd5925f31ace119584bd020278d8e Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Fri, 19 Dec 2025 13:02:26 +0100 Subject: [PATCH 5/9] Bump version to next major release 6.0.0 Java version upgrade is a breaking change. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index abc7312d..dc210b33 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ edu.hm.hafner codingstyle - 5.26.0-SNAPSHOT + 6.0.0-SNAPSHOT jar Java coding style From 739c6f7ed5d0562624f8823b3d9b05cf1290c22a Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 24 Dec 2025 12:25:03 +0100 Subject: [PATCH 6/9] Fix typo --- LIESMICH.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LIESMICH.md b/LIESMICH.md index bc195c03..697abf4d 100644 --- a/LIESMICH.md +++ b/LIESMICH.md @@ -25,7 +25,7 @@ entsprechenden IntelliJ Plugins). Zusätzlich sind die [IntelliJ Code Inspections](https://www.jetbrains.com/help/idea/code-inspection.html) gemäß meiner Richtlinien konfiguriert. Aktuell können diese allerdings noch nicht automatisch im Build überprüft werden (siehe [#7](https://github.com/uhafner/codingstyle/issues/7)). Insgesamt ist damit sichergestellt, -dass immer die gleichen Warnungen angezeigt werden - egal wie und wo die Java Dateien weiterverarbeitet werden. +dass immer die gleichen Warnungen angezeigt werden - egal wie und wo die Java-Dateien weiterverarbeitet werden. Für SpotBugs und PMD ist der Umweg über das Build Management Tool [Maven](http://maven.apache.org/) erforderlich (die entsprechenden IntelliJ Plugins sind leider aus meiner Sicht noch nicht ausgereift genug bzw. verwenden eine separate Konfiguration). Die Verwendung von Maven hat zudem den Vorteil, dass die Ergebnisse hinterher leicht in den Continuous Integration Server From f4dfe70ad68200ef100068627160a4f58e8a6642 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 24 Dec 2025 15:23:56 +0100 Subject: [PATCH 7/9] Update copyright date --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a2828e73..1c91f10a 100644 --- a/LICENSE +++ b/LICENSE @@ -6,7 +6,7 @@ http://creativecommons.org/licenses/by/4.0/ MIT License -Copyright (c) 2014-2023 Dr. Ullrich Hafner +Copyright (c) 2014-2026 Dr. Ullrich Hafner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation From 14b318011834ab1c9083e49d0657a6a2934dad0b Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Sat, 3 Jan 2026 21:33:32 +0100 Subject: [PATCH 8/9] Sort OpenRewrite rules --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index dc210b33..0db5d74e 100644 --- a/pom.xml +++ b/pom.xml @@ -357,19 +357,19 @@ org.openrewrite.maven.BestPractices org.openrewrite.maven.RemoveRedundantDependencyVersions org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID - org.openrewrite.staticanalysis.MissingOverrideAnnotation org.openrewrite.staticanalysis.CodeCleanup org.openrewrite.staticanalysis.CommonStaticAnalysis + org.openrewrite.staticanalysis.MissingOverrideAnnotation org.openrewrite.staticanalysis.RemoveExtraSemicolons org.openrewrite.java.migrate.UpgradeToJava21 + org.openrewrite.java.migrate.util.JavaUtilAPIs org.openrewrite.java.migrate.util.SequencedCollection + org.openrewrite.java.migrate.lang.StringRulesRecipes org.openrewrite.java.migrate.lang.var.UseVarForObject org.openrewrite.java.migrate.net.JavaNetAPIs - org.openrewrite.java.migrate.util.JavaUtilAPIs - org.openrewrite.java.migrate.lang.StringRulesRecipes - org.openrewrite.java.format.RemoveTrailingWhitespace org.openrewrite.java.format.BlankLines org.openrewrite.java.format.EmptyNewlineAtEndOfFile + org.openrewrite.java.format.RemoveTrailingWhitespace org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertions From c1cfccb4a0a4342144d5f60490b119ecbdcefa4a Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Sat, 3 Jan 2026 22:54:02 +0100 Subject: [PATCH 9/9] Enforce the usage of Java 21 or 25 --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0db5d74e..938b071b 100644 --- a/pom.xml +++ b/pom.xml @@ -724,7 +724,8 @@ - ${java.jdk.version} + [21,22),[25,26) + Java LTS 21 or 25 is required to build this project.