You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/08/22 13:58:26 UTC

(commons-validator) branch master updated (655ba0ca -> 6d45d582)

This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git


    from 655ba0ca Bump codeql-action from 4.37.6 to 4.37.7
     new 7fbb6425 Fix SpotBugs USO_UNSAFE_METHOD_SYNCHRONIZATION in DomainValidator.
     new 6d45d582 Bump org.apache.commons:commons-parent from 103 to 104.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |   2 +-
 src/changes/changes.xml                            |   3 +-
 .../validator/routines/DomainValidator.java        | 178 +++++++++++----------
 3 files changed, 98 insertions(+), 85 deletions(-)


(commons-validator) 02/02: Bump org.apache.commons:commons-parent from 103 to 104.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git

commit 6d45d58234bfd95b76bbb4995aa1d5908bea977f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 22 09:58:19 2026 -0400

    Bump org.apache.commons:commons-parent from 103 to 104.
    
    Fix Checkstyle issues.
---
 pom.xml                 | 2 +-
 src/changes/changes.xml | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index e6d43168..160cf433 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
   <parent>
     <groupId>org.apache.commons</groupId>
     <artifactId>commons-parent</artifactId>
-    <version>103</version>
+    <version>104</version>
   </parent>
   <groupId>commons-validator</groupId>
   <artifactId>commons-validator</artifactId>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5916bf96..3cfa7ae4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Drop the symbol separator in the currency and percent re-parse (#430).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Count unpaired carriage returns in adjustForLineEnding (#431).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Validate path, query and fragment for authority-less file URLs (#432).</action>
+    <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs USO_UNSAFE_METHOD_SYNCHRONIZATION in DomainValidator.</action>
     <!-- ADD -->
     <!-- UPDATE -->
   </release>
@@ -126,7 +127,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ValidatorException.ValidatorException(String, Object...) (#391).</action>
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ValidatorException(String, Throwable) (#392).</action>
     <!-- UPDATE -->
-    <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 92 to 103 #377.</action>
+    <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 92 to 104 #377.</action>
     <action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-logging:commons-logging from 1.3.5 to 1.4.0.</action>
     <action type="update" dev="sebb">DomainValidator: Changes from 2026062300, Last Updated Tue Jun 23 07:07:01 2026 UTC.</action>
     <action type="update" dev="sebb">DomainValidatorTest: reflection no longer needed to access arrays.</action>


(commons-validator) 01/02: Fix SpotBugs USO_UNSAFE_METHOD_SYNCHRONIZATION in DomainValidator.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git

commit 7fbb64258b7c47e83955119c6398ad937a48b330
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 22 09:58:14 2026 -0400

    Fix SpotBugs USO_UNSAFE_METHOD_SYNCHRONIZATION in DomainValidator.
---
 .../validator/routines/DomainValidator.java        | 178 +++++++++++----------
 1 file changed, 95 insertions(+), 83 deletions(-)

diff --git a/src/main/java/org/apache/commons/validator/routines/DomainValidator.java b/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
index c3566de0..3a0a1121 100644
--- a/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
+++ b/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
@@ -1822,6 +1822,8 @@ public class DomainValidator implements Serializable {
     // WARNING: this array MUST be sorted, otherwise it cannot be searched reliably using binary search
     private static String[] localTLDsPlus = EMPTY_STRING_ARRAY; //NOPMD @GuardedBy("this")
 
+    private static final Object LOCK = new Object();
+
     /**
      * Tests if a sorted array contains the specified key
      *
@@ -1838,9 +1840,11 @@ public class DomainValidator implements Serializable {
      *
      * @return The singleton instance of this validator.
      */
-    public static synchronized DomainValidator getInstance() {
-        inUse = true;
-        return LazyHolder.DOMAIN_VALIDATOR;
+    public static DomainValidator getInstance() {
+        synchronized (LOCK) {
+            inUse = true;
+            return LazyHolder.DOMAIN_VALIDATOR;
+        }
     }
 
     /**
@@ -1849,12 +1853,14 @@ public class DomainValidator implements Serializable {
      * @param allowLocal Whether local addresses are considered valid.
      * @return The singleton instance of this validator.
      */
-    public static synchronized DomainValidator getInstance(final boolean allowLocal) {
-        inUse = true;
-        if (allowLocal) {
-            return LazyHolder.DOMAIN_VALIDATOR_WITH_LOCAL;
+    public static DomainValidator getInstance(final boolean allowLocal) {
+        synchronized (LOCK) {
+            inUse = true;
+            if (allowLocal) {
+                return LazyHolder.DOMAIN_VALIDATOR_WITH_LOCAL;
+            }
+            return LazyHolder.DOMAIN_VALIDATOR;
         }
-        return LazyHolder.DOMAIN_VALIDATOR;
     }
 
     /**
@@ -1867,9 +1873,11 @@ public class DomainValidator implements Serializable {
      * @return An instance of this validator.
      * @since 1.7
      */
-    public static synchronized DomainValidator getInstance(final boolean allowLocal, final List<Item> items) {
-        inUse = true;
-        return new DomainValidator(allowLocal, items);
+    public static DomainValidator getInstance(final boolean allowLocal, final List<Item> items) {
+        synchronized (LOCK) {
+            inUse = true;
+            return new DomainValidator(allowLocal, items);
+        }
     }
 
     /**
@@ -1880,43 +1888,45 @@ public class DomainValidator implements Serializable {
      * @throws IllegalArgumentException if the table type is unexpected (should not happen).
      * @since 1.5.1
      */
-    public static synchronized String[] getTLDEntries(final ArrayType table) {
-        final String[] array;
-        switch (table) {
-        case COUNTRY_CODE_MINUS:
-            array = countryCodeTLDsMinus;
-            break;
-        case COUNTRY_CODE_PLUS:
-            array = countryCodeTLDsPlus;
-            break;
-        case GENERIC_MINUS:
-            array = genericTLDsMinus;
-            break;
-        case GENERIC_PLUS:
-            array = genericTLDsPlus;
-            break;
-        case LOCAL_MINUS:
-            array = localTLDsMinus;
-            break;
-        case LOCAL_PLUS:
-            array = localTLDsPlus;
-            break;
-        case GENERIC_RO:
-            array = GENERIC_TLDS;
-            break;
-        case COUNTRY_CODE_RO:
-            array = COUNTRY_CODE_TLDS;
-            break;
-        case INFRASTRUCTURE_RO:
-            array = INFRASTRUCTURE_TLDS;
-            break;
-        case LOCAL_RO:
-            array = LOCAL_TLDS;
-            break;
-        default:
-            throw new IllegalArgumentException(UNEXPECTED_ENUM_VALUE + table);
+    public static String[] getTLDEntries(final ArrayType table) {
+        synchronized (LOCK) {
+            final String[] array;
+            switch (table) {
+            case COUNTRY_CODE_MINUS:
+                array = countryCodeTLDsMinus;
+                break;
+            case COUNTRY_CODE_PLUS:
+                array = countryCodeTLDsPlus;
+                break;
+            case GENERIC_MINUS:
+                array = genericTLDsMinus;
+                break;
+            case GENERIC_PLUS:
+                array = genericTLDsPlus;
+                break;
+            case LOCAL_MINUS:
+                array = localTLDsMinus;
+                break;
+            case LOCAL_PLUS:
+                array = localTLDsPlus;
+                break;
+            case GENERIC_RO:
+                array = GENERIC_TLDS;
+                break;
+            case COUNTRY_CODE_RO:
+                array = COUNTRY_CODE_TLDS;
+                break;
+            case INFRASTRUCTURE_RO:
+                array = INFRASTRUCTURE_TLDS;
+                break;
+            case LOCAL_RO:
+                array = LOCAL_TLDS;
+                break;
+            default:
+                throw new IllegalArgumentException(UNEXPECTED_ENUM_VALUE + table);
+            }
+            return Arrays.copyOf(array, array.length); // clone the array
         }
-        return Arrays.copyOf(array, array.length); // clone the array
     }
 
     /*
@@ -2068,42 +2078,44 @@ public class DomainValidator implements Serializable {
      * @throws IllegalArgumentException if one of the read-only tables is requested.
      * @since 1.5.0
      */
-    public static synchronized void updateTLDOverride(final ArrayType table, final String... tlds) {
-        if (inUse) {
-            throw new IllegalStateException("Can only invoke this method before calling getInstance");
-        }
-        final String[] copy = new String[tlds.length];
-        // Comparisons are always done with lower-case entries
-        for (int i = 0; i < tlds.length; i++) {
-            copy[i] = tlds[i].toLowerCase(Locale.ENGLISH);
-        }
-        Arrays.sort(copy);
-        switch (table) {
-        case COUNTRY_CODE_MINUS:
-            countryCodeTLDsMinus = copy;
-            break;
-        case COUNTRY_CODE_PLUS:
-            countryCodeTLDsPlus = copy;
-            break;
-        case GENERIC_MINUS:
-            genericTLDsMinus = copy;
-            break;
-        case GENERIC_PLUS:
-            genericTLDsPlus = copy;
-            break;
-        case LOCAL_MINUS:
-            localTLDsMinus = copy;
-            break;
-        case LOCAL_PLUS:
-            localTLDsPlus = copy;
-            break;
-        case COUNTRY_CODE_RO:
-        case GENERIC_RO:
-        case INFRASTRUCTURE_RO:
-        case LOCAL_RO:
-            throw new IllegalArgumentException("Cannot update the table: " + table);
-        default:
-            throw new IllegalArgumentException(UNEXPECTED_ENUM_VALUE + table);
+    public static void updateTLDOverride(final ArrayType table, final String... tlds) {
+        synchronized (LOCK) {
+            if (inUse) {
+                throw new IllegalStateException("Can only invoke this method before calling getInstance");
+            }
+            final String[] copy = new String[tlds.length];
+            // Comparisons are always done with lower-case entries
+            for (int i = 0; i < tlds.length; i++) {
+                copy[i] = tlds[i].toLowerCase(Locale.ENGLISH);
+            }
+            Arrays.sort(copy);
+            switch (table) {
+            case COUNTRY_CODE_MINUS:
+                countryCodeTLDsMinus = copy;
+                break;
+            case COUNTRY_CODE_PLUS:
+                countryCodeTLDsPlus = copy;
+                break;
+            case GENERIC_MINUS:
+                genericTLDsMinus = copy;
+                break;
+            case GENERIC_PLUS:
+                genericTLDsPlus = copy;
+                break;
+            case LOCAL_MINUS:
+                localTLDsMinus = copy;
+                break;
+            case LOCAL_PLUS:
+                localTLDsPlus = copy;
+                break;
+            case COUNTRY_CODE_RO:
+            case GENERIC_RO:
+            case INFRASTRUCTURE_RO:
+            case LOCAL_RO:
+                throw new IllegalArgumentException("Cannot update the table: " + table);
+            default:
+                throw new IllegalArgumentException(UNEXPECTED_ENUM_VALUE + table);
+            }
         }
     }