From 5563e06599ee9f153103320639485103a380ec8f Mon Sep 17 00:00:00 2001 From: Venkata Naga Sai Srikanth Gollapudi <42247688+gollapudisrikanth@users.noreply.github.com> Date: Wed, 29 Apr 2026 22:50:08 -0500 Subject: [PATCH 1/2] SpringJavadocCheck now permits tag descriptions that start with consecutive uppercase letters (e.g., "JNI", "HTML", "URL") instead of reporting a badCase violation. Single capitalized words are still rejected. Closes gh-468 Signed-off-by: Venkata Naga Sai Srikanth Gollapudi <42247688+GollapudiSrikanth@users.noreply.github.com> --- .../checkstyle/check/SpringJavadocCheck.java | 21 ++++++++++++++++++- .../test/resources/source/JavadocValid.java | 10 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java index 56f7ea63..2b6b5b1a 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java @@ -35,6 +35,7 @@ * Checks that the javadoc comments follow Spring conventions. * * @author Phillip Webb + * @author Venkata Naga Sai Srikanth Gollapudi */ public class SpringJavadocCheck extends AbstractSpringCheck { @@ -245,9 +246,27 @@ private void checkAnnotationFieldJavaDoc(DetailAST ast, TextBlock javadoc) { } private boolean startsWithUppercase(String description) { - return description.length() > 0 && Character.isUpperCase(description.charAt(0)); + if(description.length() > 0 || Character.isUpperCase(description.charAt(0))) { + return false; + } + return !startWithAcronym(description); } + private boolean startWithAcronym(String description) { + int upperCount = 0; + for (int i = 0; i < description.length(); i++) { + char ch= description.charAt(i); + if (Character.isUpperCase(ch)) { + upperCount++; + } + else { + break; + } + + } + return upperCount >= 2; + } + private void checkForNonJavadocComments(TextBlock block) { if (block == null) { return; diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java index 6584ef36..367e3169 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java @@ -19,6 +19,7 @@ * * @param this is a valid param * @author Phillip Webb + * @author Venkata Naga Sai Srikanth Gollapudi */ public class JavadocValid { @@ -46,6 +47,15 @@ public void test2(String something) { public String test3(String something) throws RuntimeException { } + /** + * Do something with acronyms. + * @param something JNI hints for the thing + * @return the thing + * @throws RuntimeException on the error + */ + public String test4(String something) throws RuntimeException { + } + /** * Class with a numeric date since. * @since 28.12.2003 From 809d5f036c301f132030b68b1933fcc27975c9ce Mon Sep 17 00:00:00 2001 From: Venkata Naga Sai Srikanth Gollapudi <42247688+gollapudisrikanth@users.noreply.github.com> Date: Thu, 30 Apr 2026 22:58:00 -0500 Subject: [PATCH 2/2] suggested changes Closes gh-468 Signed-off-by: Venkata Naga Sai Srikanth Gollapudi <42247688+GollapudiSrikanth@users.noreply.github.com> --- .../checkstyle/check/SpringJavadocCheck.java | 35 +++++++++---------- .../test/resources/source/JavadocValid.java | 16 ++++----- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java index 2b6b5b1a..7e353af9 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringJavadocCheck.java @@ -154,7 +154,7 @@ private void checkTagCase(DetailAST ast, TextBlock javadoc) { Matcher matcher = pattern.matcher(text[i]); if (matcher.find()) { String description = matcher.group(1).trim(); - if (startsWithUppercase(description)) { + if (!hasCorrectCase(description)) { log(javadoc.getStartLineNo() + i, text[i].length() - description.length(), "javadoc.badCase"); } } @@ -245,27 +245,24 @@ private void checkAnnotationFieldJavaDoc(DetailAST ast, TextBlock javadoc) { } } + private boolean hasCorrectCase(String description) { + return startsWithAcronym(description) || !startsWithUppercase(description); + } + private boolean startsWithUppercase(String description) { - if(description.length() > 0 || Character.isUpperCase(description.charAt(0))) { - return false; - } - return !startWithAcronym(description); + return !description.isEmpty() && Character.isUpperCase(description.charAt(0)); } - private boolean startWithAcronym(String description) { - int upperCount = 0; - for (int i = 0; i < description.length(); i++) { - char ch= description.charAt(i); - if (Character.isUpperCase(ch)) { - upperCount++; - } - else { - break; - } - - } - return upperCount >= 2; - } + private boolean startsWithAcronym(String description) { + int i = 0; + while (i < description.length() && Character.isLetter(description.charAt(i))) { + if (!Character.isUpperCase(description.charAt(i))) { + return false; + } + i++; + } + return i >= 2; + } private void checkForNonJavadocComments(TextBlock block) { if (block == null) { diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java index 367e3169..68bfc9ae 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/JavadocValid.java @@ -47,14 +47,14 @@ public void test2(String something) { public String test3(String something) throws RuntimeException { } - /** - * Do something with acronyms. - * @param something JNI hints for the thing - * @return the thing - * @throws RuntimeException on the error - */ - public String test4(String something) throws RuntimeException { - } + /** + * Do something with acronyms. + * @param something JNI hints for the thing + * @return the thing + * @throws RuntimeException on the error + */ + public String test4(String something) throws RuntimeException { + } /** * Class with a numeric date since.