This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 64409917b54d4f9b382db0ff159bbbb7c11af540 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Apr 23 09:30:16 2024 -0400 Make internal constructors private - org.apache.commons.text.StrLookup.MapStrLookup.MapStrLookup(Map) - org.apache.commons.text.StrLookup.SystemPropertiesStrLookup.SystemPropertiesStrLookup() --- src/changes/changes.xml | 2 ++ src/main/java/org/apache/commons/text/StrLookup.java | 9 ++++++++- src/test/java/org/apache/commons/text/StrSubstitutorTest.java | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4b8da4b4..d9f40b6b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -49,6 +49,8 @@ The <action> type attribute can be add,update,fix,remove. <!-- FIX --> <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 22.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix build on Java 23-ea.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">Make internal constructor private for org.apache.commons.text.StrLookup.MapStrLookup.MapStrLookup(Map).</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">Make internal constructor private for org.apache.commons.text.StrLookup.SystemPropertiesStrLookup.SystemPropertiesStrLookup().</action> <!-- UPDATE --> <action type="udpate" dev="ggregory" due-to="Gary Gregory">Bump tests on Java >= 22 org.graalvm.*:* from 24.0.0 to 24.0.1.</action> </release> diff --git a/src/main/java/org/apache/commons/text/StrLookup.java b/src/main/java/org/apache/commons/text/StrLookup.java index 57a206ad..1ae41a48 100644 --- a/src/main/java/org/apache/commons/text/StrLookup.java +++ b/src/main/java/org/apache/commons/text/StrLookup.java @@ -61,7 +61,7 @@ public abstract class StrLookup<V> implements StringLookup { * * @param map the map of keys to values, may be null */ - MapStrLookup(final Map<String, V> map) { + private MapStrLookup(final Map<String, V> map) { this.map = map != null ? map : Collections.emptyMap(); } @@ -122,6 +122,13 @@ public abstract class StrLookup<V> implements StringLookup { */ private static final class SystemPropertiesStrLookup extends StrLookup<String> { + /** + * Private for Spotbugs SING_SINGLETON_GETTER_NOT_SYNCHRONIZED. + */ + private SystemPropertiesStrLookup() { + // default + } + /** * {@inheritDoc} This implementation directly accesses system properties. */ diff --git a/src/test/java/org/apache/commons/text/StrSubstitutorTest.java b/src/test/java/org/apache/commons/text/StrSubstitutorTest.java index abbb9e51..d532b398 100644 --- a/src/test/java/org/apache/commons/text/StrSubstitutorTest.java +++ b/src/test/java/org/apache/commons/text/StrSubstitutorTest.java @@ -195,7 +195,7 @@ public class StrSubstitutorTest { @Test public void testCreatesStrSubstitutorTakingStrLookupAndCallsReplaceTakingTwoAndThreeInts() { final Map<String, CharacterPredicates> map = new HashMap<>(); - final StrLookup.MapStrLookup<CharacterPredicates> strLookupMapStrLookup = new StrLookup.MapStrLookup<>(map); + final StrLookup<CharacterPredicates> strLookupMapStrLookup = StrLookup.mapLookup(map); final StrSubstitutor strSubstitutor = new StrSubstitutor(strLookupMapStrLookup); assertNull(strSubstitutor.replace((CharSequence) null, 0, 0)); @@ -471,7 +471,7 @@ public class StrSubstitutorTest { @Test public void testReplaceInTakingTwoAndThreeIntsReturningFalse() { final Map<String, Object> hashMap = new HashMap<>(); - final StrLookup.MapStrLookup<Object> strLookupMapStrLookup = new StrLookup.MapStrLookup<>(hashMap); + final StrLookup<Object> strLookupMapStrLookup = StrLookup.mapLookup(hashMap); final StrMatcher strMatcher = StrMatcher.tabMatcher(); final StrSubstitutor strSubstitutor = new StrSubstitutor(strLookupMapStrLookup, strMatcher, strMatcher, 'b', strMatcher);