This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new e78e9921cf org.apache.juneau.common.reflect API improvements
e78e9921cf is described below
commit e78e9921cf16311588f281574fc6308231a33d27
Author: James Bognar <[email protected]>
AuthorDate: Fri Nov 21 13:58:54 2025 -0500
org.apache.juneau.common.reflect API improvements
---
.../apache/juneau/common/collections/Cache.java | 17 +++-------
.../apache/juneau/common/collections/Cache2.java | 29 ++++++----------
.../apache/juneau/common/collections/Cache3.java | 39 +++++++++-------------
.../apache/juneau/common/collections/Cache4.java | 31 ++++++++---------
.../apache/juneau/common/collections/Cache5.java | 35 +++++++++----------
.../juneau/common/reflect/AnnotationProvider.java | 5 ++-
.../juneau/common/collections/Cache2_Test.java | 24 +++++++++----
.../juneau/common/collections/Cache3_Test.java | 14 +++++---
.../juneau/common/collections/Cache4_Test.java | 16 ++++++---
.../juneau/common/collections/Cache5_Test.java | 18 ++++++----
.../juneau/common/collections/Cache_Test.java | 18 +++++++---
11 files changed, 124 insertions(+), 122 deletions(-)
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
index 7094c2fd62..318b10e186 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
@@ -17,7 +17,6 @@
package org.apache.juneau.common.collections;
import static org.apache.juneau.common.collections.CacheMode.*;
-import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.SystemUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import static java.util.Collections.*;
@@ -454,13 +453,11 @@ public class Cache<K,V> {
* Pattern <jv>p</jv> = <jv>cache</jv>.get(<js>"[0-9]+"</js>);
* </p>
*
- * @param key The cache key. Must not be <jk>null</jk>.
+ * @param key The cache key. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
* @throws NullPointerException if no default supplier was configured.
- * @throws IllegalArgumentException if key is <jk>null</jk>.
*/
public V get(K key) {
- assertArgNotNull("key", key);
return get(key, () -> supplier.apply(key));
}
@@ -499,13 +496,11 @@ public class Cache<K,V> {
* <jsm>assert</jsm> <jv>p1</jv> == <jv>p2</jv>; <jc>// Same
instance</jc>
* </p>
*
- * @param key The cache key. Must not be <jk>null</jk>.
+ * @param key The cache key. Can be <jk>null</jk>.
* @param supplier The supplier to compute the value if it's not in the
cache. Must not be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
- * @throws IllegalArgumentException if key is <jk>null</jk>.
*/
public V get(K key, Supplier<V> supplier) {
- assertArgNotNull("key", key);
if (disableCaching)
return supplier.get();
Tuple1<K> wrapped = wrap(key);
@@ -527,13 +522,11 @@ public class Cache<K,V> {
/**
* Associates the specified value with the specified key in this cache.
*
- * @param key The cache key. Must not be <jk>null</jk>.
+ * @param key The cache key. Can be <jk>null</jk>.
* @param value The value to associate with the key.
* @return The previous value associated with the key, or <jk>null</jk>
if there was no mapping.
- * @throws IllegalArgumentException if key is <jk>null</jk>.
*/
public V put(K key, V value) {
- assertArgNotNull("key", key);
return map.put(wrap(key), value);
}
@@ -614,12 +607,10 @@ public class Cache<K,V> {
/**
* Removes the entry for the specified key from the cache.
*
- * @param key The key to remove.
+ * @param key The key to remove. Can be <jk>null</jk>.
* @return The previous value associated with the key, or <jk>null</jk>
if there was no mapping.
- * @throws IllegalArgumentException if key is <jk>null</jk>.
*/
public V remove(K key) {
- assertArgNotNull("key", key);
Tuple1<K> wrapped = wrap(key);
V result = map.remove(wrapped);
wrapperCache.remove(key); // Clean up wrapper cache
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache2.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache2.java
index ab8bfda19b..9efd3ea929 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache2.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache2.java
@@ -18,7 +18,6 @@ package org.apache.juneau.common.collections;
import static org.apache.juneau.common.collections.CacheMode.*;
-import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.SystemUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
@@ -393,14 +392,12 @@ public class Cache2<K1,K2,V> {
* User <jv>u</jv> = <jv>cache</jv>.get(<js>"tenant1"</js>, 123);
* </p>
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
* @throws NullPointerException if no default supplier was configured.
- * @throws IllegalArgumentException if key1 or key2 is <jk>null</jk>.
*/
public V get(K1 key1, K2 key2) {
- assertArgsNotNull("key1", key1, "key2", key2);
return get(key1, key2, () -> supplier.apply(key1, key2));
}
@@ -439,14 +436,12 @@ public class Cache2<K1,K2,V> {
* <jsm>assert</jsm> <jv>u1</jv> == <jv>u2</jv>; <jc>// Same
instance</jc>
* </p>
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
* @param supplier The supplier to compute the value if it's not in the
cache. Must not be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
- * @throws IllegalArgumentException if key1 or key2 is <jk>null</jk>.
*/
public V get(K1 key1, K2 key2, java.util.function.Supplier<V> supplier)
{
- assertArgsNotNull("key1", key1, "key2", key2);
if (cacheMode == NONE)
return supplier.get();
Tuple2<K1,K2> wrapped = Tuple2.of(key1, key2);
@@ -465,35 +460,31 @@ public class Cache2<K1,K2,V> {
/**
* Associates the specified value with the specified key pair.
*
- * @param key1 The first key.
- * @param key2 The second key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
* @param value The value to associate with the key pair.
* @return The previous value associated with the key pair, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if key1 or key2 is <jk>null</jk>.
*/
public V put(K1 key1, K2 key2, V value) {
- assertArgsNotNull("key1", key1, "key2", key2);
return map.put(Tuple2.of(key1, key2), value);
}
/**
* Removes the entry for the specified key pair from the cache.
*
- * @param key1 The first key.
- * @param key2 The second key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
* @return The previous value associated with the key pair, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if key1 or key2 is <jk>null</jk>.
*/
public V remove(K1 key1, K2 key2) {
- assertArgsNotNull("key1", key1, "key2", key2);
return map.remove(Tuple2.of(key1, key2));
}
/**
* Returns <jk>true</jk> if the cache contains a mapping for the
specified key pair.
*
- * @param key1 The first key.
- * @param key2 The second key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
* @return <jk>true</jk> if the cache contains the key pair.
*/
public boolean containsKey(K1 key1, K2 key2) {
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache3.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache3.java
index a134446141..528252173b 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache3.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache3.java
@@ -18,7 +18,6 @@ package org.apache.juneau.common.collections;
import static org.apache.juneau.common.collections.CacheMode.*;
-import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.SystemUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
@@ -246,30 +245,26 @@ public class Cache3<K1,K2,K3,V> {
/**
* Retrieves a cached value by key triplet using the default supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
* @throws NullPointerException if no default supplier was configured.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
*/
public V get(K1 key1, K2 key2, K3 key3) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3);
return get(key1, key2, key3, () -> supplier.apply(key1, key2,
key3));
}
/**
* Retrieves a cached value by key triplet, computing it if necessary
using the provided supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
* @param supplier The supplier to compute the value if it's not in the
cache. Must not be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
*/
public V get(K1 key1, K2 key2, K3 key3, java.util.function.Supplier<V>
supplier) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3);
if (cacheMode == NONE)
return supplier.get();
Tuple3<K1,K2,K3> wrapped = Tuple3.of(key1, key2, key3);
@@ -288,38 +283,34 @@ public class Cache3<K1,K2,K3,V> {
/**
* Associates the specified value with the specified key triplet.
*
- * @param key1 The first key.
- * @param key2 The second key.
- * @param key3 The third key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
+ * @param key3 The third key. Can be <jk>null</jk>.
* @param value The value to associate with the key triplet.
* @return The previous value associated with the key triplet, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
*/
public V put(K1 key1, K2 key2, K3 key3, V value) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3);
return map.put(Tuple3.of(key1, key2, key3), value);
}
/**
* Removes the entry for the specified key triplet from the cache.
*
- * @param key1 The first key.
- * @param key2 The second key.
- * @param key3 The third key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
+ * @param key3 The third key. Can be <jk>null</jk>.
* @return The previous value associated with the key triplet, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
*/
public V remove(K1 key1, K2 key2, K3 key3) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3);
return map.remove(Tuple3.of(key1, key2, key3));
}
/**
* Returns <jk>true</jk> if the cache contains a mapping for the
specified key triplet.
*
- * @param key1 The first key.
- * @param key2 The second key.
- * @param key3 The third key.
+ * @param key1 The first key. Can be <jk>null</jk>.
+ * @param key2 The second key. Can be <jk>null</jk>.
+ * @param key3 The third key. Can be <jk>null</jk>.
* @return <jk>true</jk> if the cache contains the key triplet.
*/
public boolean containsKey(K1 key1, K2 key2, K3 key3) {
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache4.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache4.java
index e61958a23a..d1ae1bf367 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache4.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache4.java
@@ -18,7 +18,6 @@ package org.apache.juneau.common.collections;
import static org.apache.juneau.common.collections.CacheMode.*;
-import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.SystemUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
@@ -236,32 +235,30 @@ public class Cache4<K1,K2,K3,K4,V> {
/**
* Retrieves a cached value by four-part key using the default supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
- * @param key4 Fourth key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
+ * @param key4 Fourth key component. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
* @throws NullPointerException if no default supplier was configured.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V get(K1 key1, K2 key2, K3 key3, K4 key4) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4);
return get(key1, key2, key3, key4, () -> supplier.apply(key1,
key2, key3, key4));
}
/**
* Retrieves a cached value by four-part key, computing it if necessary
using the provided supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
- * @param key4 Fourth key component. Must not be <jk>null</jk>.
- * @param supplier The supplier to compute the value if it's not in the
cache. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
+ * @param key4 Fourth key component. Can be <jk>null</jk>.
+ * @param supplier The supplier to compute the value if it's not in the
cache. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V get(K1 key1, K2 key2, K3 key3, K4 key4,
java.util.function.Supplier<V> supplier) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4);
if (cacheMode == NONE)
return supplier.get();
Tuple4<K1,K2,K3,K4> wrapped = Tuple4.of(key1, key2, key3, key4);
@@ -286,10 +283,9 @@ public class Cache4<K1,K2,K3,K4,V> {
* @param key4 The fourth key.
* @param value The value to associate with the four-part key.
* @return The previous value associated with the four-part key, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V put(K1 key1, K2 key2, K3 key3, K4 key4, V value) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4);
return map.put(Tuple4.of(key1, key2, key3, key4), value);
}
@@ -301,10 +297,9 @@ public class Cache4<K1,K2,K3,K4,V> {
* @param key3 The third key.
* @param key4 The fourth key.
* @return The previous value associated with the four-part key, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V remove(K1 key1, K2 key2, K3 key3, K4 key4) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4);
return map.remove(Tuple4.of(key1, key2, key3, key4));
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache5.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache5.java
index ee7c5afb86..9c706288f0 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache5.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache5.java
@@ -18,7 +18,6 @@ package org.apache.juneau.common.collections;
import static org.apache.juneau.common.collections.CacheMode.*;
-import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.SystemUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
@@ -242,34 +241,32 @@ public class Cache5<K1,K2,K3,K4,K5,V> {
/**
* Retrieves a cached value by five-part key using the default supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
- * @param key4 Fourth key component. Must not be <jk>null</jk>.
- * @param key5 Fifth key component. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
+ * @param key4 Fourth key component. Can be <jk>null</jk>.
+ * @param key5 Fifth key component. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
* @throws NullPointerException if no default supplier was configured.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V get(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4, "key5", key5);
return get(key1, key2, key3, key4, key5, () ->
supplier.apply(key1, key2, key3, key4, key5));
}
/**
* Retrieves a cached value by five-part key, computing it if necessary
using the provided supplier.
*
- * @param key1 First key component. Must not be <jk>null</jk>.
- * @param key2 Second key component. Must not be <jk>null</jk>.
- * @param key3 Third key component. Must not be <jk>null</jk>.
- * @param key4 Fourth key component. Must not be <jk>null</jk>.
- * @param key5 Fifth key component. Must not be <jk>null</jk>.
- * @param supplier The supplier to compute the value if it's not in the
cache. Must not be <jk>null</jk>.
+ * @param key1 First key component. Can be <jk>null</jk>.
+ * @param key2 Second key component. Can be <jk>null</jk>.
+ * @param key3 Third key component. Can be <jk>null</jk>.
+ * @param key4 Fourth key component. Can be <jk>null</jk>.
+ * @param key5 Fifth key component. Can be <jk>null</jk>.
+ * @param supplier The supplier to compute the value if it's not in the
cache. Can be <jk>null</jk>.
* @return The cached or computed value. May be <jk>null</jk> if the
supplier returns <jk>null</jk>.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V get(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5,
java.util.function.Supplier<V> supplier) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4, "key5", key5);
if (cacheMode == NONE)
return supplier.get();
Tuple5<K1,K2,K3,K4,K5> wrapped = Tuple5.of(key1, key2, key3,
key4, key5);
@@ -295,10 +292,9 @@ public class Cache5<K1,K2,K3,K4,K5,V> {
* @param key5 The fifth key.
* @param value The value to associate with the five-part key.
* @return The previous value associated with the five-part key, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V put(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, V value) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4, "key5", key5);
return map.put(Tuple5.of(key1, key2, key3, key4, key5), value);
}
@@ -311,10 +307,9 @@ public class Cache5<K1,K2,K3,K4,K5,V> {
* @param key4 The fourth key.
* @param key5 The fifth key.
* @return The previous value associated with the five-part key, or
<jk>null</jk> if there was no mapping.
- * @throws IllegalArgumentException if any key is <jk>null</jk>.
+ *
*/
public V remove(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) {
- assertArgsNotNull("key1", key1, "key2", key2, "key3", key3,
"key4", key4, "key5", key5);
return map.remove(Tuple5.of(key1, key2, key3, key4, key5));
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
index 8418e5a16d..fb8bc0826a 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/reflect/AnnotationProvider.java
@@ -229,7 +229,7 @@ public class AnnotationProvider {
* <br>Valid values: <c>TRUE</c>, <c>FALSE</c> (case-insensitive)
* <br>Default: <c>FALSE</c>
*/
- private static final boolean ENABLE_NEW_CODE =
b(System.getProperty("juneau.annotationProvider.useNewCode"));
+ private static final boolean ENABLE_NEW_CODE = true;
/**
* Default instance.
@@ -713,6 +713,9 @@ public class AnnotationProvider {
@SuppressWarnings("unchecked")
public Stream<AnnotationInfo<? extends Annotation>> find(ClassInfo
clazz, AnnotationTraversal... traversals) {
trackCall("find(ClassInfo, AnnotationTraversal...)");
+ if (ENABLE_NEW_CODE)
+ return (Stream<AnnotationInfo<? extends
Annotation>>)(Stream<?>)findNew(null, clazz, traversals).stream();
+
assertArgNotNull("clazz", clazz);
if (traversals.length == 0)
traversals = a(PARENTS, PACKAGE);
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache2_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache2_Test.java
index 793a1cb370..1dafb527c6 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache2_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache2_Test.java
@@ -147,21 +147,31 @@ class Cache2_Test extends TestBase {
@Test
void c01_nullKeys_defaultSupplier() {
var x = Cache2.of(String.class, Integer.class, String.class)
- .supplier((k1, k2) -> "value")
+ .supplier((k1, k2) -> "value-" + k1 + "-" + k2)
.build();
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
123));
- assertThrows(IllegalArgumentException.class, () ->
x.get("user", null));
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
null));
+ // Null keys are now allowed
+ assertEquals("value-null-123", x.get(null, 123));
+ assertEquals("value-user-null", x.get("user", null));
+ assertEquals("value-null-null", x.get(null, null));
+
+ // Cached values should be returned on subsequent calls
+ assertEquals("value-null-123", x.get(null, 123));
+ assertEquals("value-user-null", x.get("user", null));
}
@Test
void c02_nullKeys_overrideSupplier() {
var x = Cache2.of(String.class, Integer.class,
String.class).build();
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
123, () -> "value"));
- assertThrows(IllegalArgumentException.class, () ->
x.get("user", null, () -> "value"));
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
null, () -> "value"));
+ // Null keys are now allowed
+ assertEquals("value", x.get(null, 123, () -> "value"));
+ assertEquals("value", x.get("user", null, () -> "value"));
+ assertEquals("value", x.get(null, null, () -> "value"));
+
+ // Cached values should be returned on subsequent calls
+ assertEquals("value", x.get(null, 123, () ->
"should-not-be-called"));
+ assertEquals("value", x.get("user", null, () ->
"should-not-be-called"));
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache3_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache3_Test.java
index d34df21009..bfebdbb733 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache3_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache3_Test.java
@@ -65,12 +65,18 @@ class Cache3_Test extends TestBase {
@Test
void a03_nullKeys() {
var x = Cache3.of(String.class, String.class, Integer.class,
String.class)
- .supplier((k1, k2, k3) -> "value")
+ .supplier((k1, k2, k3) -> "value-" + k1 + "-" + k2 +
"-" + k3)
.build();
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
"US", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
null, 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", null));
+ // Null keys are now allowed
+ assertEquals("value-null-US-1", x.get(null, "US", 1));
+ assertEquals("value-en-null-1", x.get("en", null, 1));
+ assertEquals("value-en-US-null", x.get("en", "US", null));
+ assertEquals("value-null-null-null", x.get(null, null, null));
+
+ // Cached values should be returned on subsequent calls
+ assertEquals("value-null-US-1", x.get(null, "US", 1));
+ assertEquals("value-en-null-1", x.get("en", null, 1));
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache4_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache4_Test.java
index 41005643fe..b132d56673 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache4_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache4_Test.java
@@ -65,13 +65,19 @@ class Cache4_Test extends TestBase {
@Test
void a03_nullKeys() {
var x = Cache4.of(String.class, String.class, String.class,
Integer.class, String.class)
- .supplier((k1, k2, k3, k4) -> "value")
+ .supplier((k1, k2, k3, k4) -> "value-" + k1 + "-" + k2
+ "-" + k3 + "-" + k4)
.build();
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
"US", "formal", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
null, "formal", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", null, 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", "formal", null));
+ // Null keys are now allowed
+ assertEquals("value-null-US-formal-1", x.get(null, "US",
"formal", 1));
+ assertEquals("value-en-null-formal-1", x.get("en", null,
"formal", 1));
+ assertEquals("value-en-US-null-1", x.get("en", "US", null, 1));
+ assertEquals("value-en-US-formal-null", x.get("en", "US",
"formal", null));
+ assertEquals("value-null-null-null-null", x.get(null, null,
null, null));
+
+ // Cached values should be returned on subsequent calls
+ assertEquals("value-null-US-formal-1", x.get(null, "US",
"formal", 1));
+ assertEquals("value-en-null-formal-1", x.get("en", null,
"formal", 1));
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache5_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache5_Test.java
index 696ea8df47..0937f787f8 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache5_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache5_Test.java
@@ -65,14 +65,20 @@ class Cache5_Test extends TestBase {
@Test
void a03_nullKeys() {
var x = Cache5.of(String.class, String.class, String.class,
String.class, Integer.class, String.class)
- .supplier((k1, k2, k3, k4, k5) -> "value")
+ .supplier((k1, k2, k3, k4, k5) -> "value-" + k1 + "-" +
k2 + "-" + k3 + "-" + k4 + "-" + k5)
.build();
- assertThrows(IllegalArgumentException.class, () -> x.get(null,
"US", "west", "formal", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
null, "west", "formal", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", null, "formal", 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", "west", null, 1));
- assertThrows(IllegalArgumentException.class, () -> x.get("en",
"US", "west", "formal", null));
+ // Null keys are now allowed
+ assertEquals("value-null-US-west-formal-1", x.get(null, "US",
"west", "formal", 1));
+ assertEquals("value-en-null-west-formal-1", x.get("en", null,
"west", "formal", 1));
+ assertEquals("value-en-US-null-formal-1", x.get("en", "US",
null, "formal", 1));
+ assertEquals("value-en-US-west-null-1", x.get("en", "US",
"west", null, 1));
+ assertEquals("value-en-US-west-formal-null", x.get("en", "US",
"west", "formal", null));
+ assertEquals("value-null-null-null-null-null", x.get(null,
null, null, null, null));
+
+ // Cached values should be returned on subsequent calls
+ assertEquals("value-null-US-west-formal-1", x.get(null, "US",
"west", "formal", 1));
+ assertEquals("value-en-null-west-formal-1", x.get("en", null,
"west", "formal", 1));
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache_Test.java
index 954858ce09..51b5bc54a3 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/common/collections/Cache_Test.java
@@ -100,12 +100,20 @@ class Cache_Test extends TestBase {
// Null key handling
//====================================================================================================
- @Test void a04_nullKey_throwsException() {
- var cache = Cache.of(String.class, String.class).build();
+ @Test void a04_nullKey_allowed() {
+ var cache = Cache.of(String.class, String.class)
+ .supplier(k -> "value-" + k)
+ .build();
- // Null keys are not allowed and throw IllegalArgumentException
- assertThrows(IllegalArgumentException.class, () ->
cache.get(null, () -> "value"));
- assertThrows(IllegalArgumentException.class, () ->
cache.get(null));
+ // Null keys are now allowed
+ assertEquals("value-null", cache.get(null, () -> "value-null"));
+
+ // Verify caching works with null keys
+ assertEquals("value-null", cache.get(null)); // Cached (hit #1)
+ assertEquals(1, cache.getCacheHits());
+
+ assertEquals("value-null", cache.get(null)); // Cached (hit #2)
+ assertEquals(2, cache.getCacheHits());
}
//====================================================================================================