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 f9577d4e48 Fix Java 21 unit test failure.
f9577d4e48 is described below

commit f9577d4e4848885c212aa35255832eb0975e3353
Author: James Bognar <[email protected]>
AuthorDate: Mon Feb 2 10:46:02 2026 -0500

    Fix Java 21 unit test failure.
---
 .../apache/juneau/commons/reflect/ClassInfo.java   |  3 +-
 .../juneau/commons/reflect/ReflectionUtils.java    | 27 ++++++++++++++++
 .../src/main/java/org/apache/juneau/ClassMeta.java |  5 ++-
 .../juneau/commons/reflect/ClassInfo_Test.java     | 36 ++++++++++++++--------
 4 files changed, 54 insertions(+), 17 deletions(-)

diff --git 
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
 
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
index 1d7af58f8f..999831d46e 100644
--- 
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
+++ 
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
@@ -1666,7 +1666,8 @@ public class ClassInfo extends ElementInfo implements 
Annotatable, Type, Compara
         *
         * <h5 class='section'>Notes:</h5>
         * <ul class='spaced-list'>
-        *      <li>This method behaves similarly to Java's {@link 
Class#getMethods()}, returning only public methods.
+        *      <li>This method behaves similarly to Java's {@link 
Class#getMethods()}, returning only public methods from this class and parent 
classes/interfaces.
+        *      <li>Bridge and synthetic methods are included (matching {@link 
Class#getMethods()} behavior).
         *      <li>Methods defined on the {@link Object} class are excluded 
from the results.
         * </ul>
         *
diff --git 
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ReflectionUtils.java
 
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ReflectionUtils.java
index 194ee916d4..0065e79e02 100644
--- 
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ReflectionUtils.java
+++ 
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ReflectionUtils.java
@@ -157,6 +157,33 @@ public class ReflectionUtils {
                return ClassInfo.of(o);
        }
 
+       /**
+        * Converts a class to an enum class, suppressing rawtypes warnings.
+        *
+        * <p>
+        * This utility method wraps {@link Class#asSubclass(Class)} for enum 
classes and suppresses
+        * the rawtypes warning that occurs when converting to {@code Class<? 
extends Enum>} for use
+        * with methods like {@link EnumSet#allOf(Class)}.
+        *
+        * <h5 class='section'>Example:</h5>
+        * <p class='bjava'>
+        *      <jc>// Instead of:</jc>
+        *      <ja>@SuppressWarnings</ja>(<js>"rawtypes"</js>)
+        *      Class&lt;? <jk>extends</jk> Enum&gt; <jv>enumClass</jv> = 
<jv>clazz</jv>.asSubclass(Enum.<jk>class</jk>);
+        *
+        *      <jc>// Use:</jc>
+        *      Class&lt;? <jk>extends</jk> Enum&gt; <jv>enumClass</jv> = 
ReflectionUtils.<jsm>asEnumClass</jsm>(<jv>clazz</jv>);
+        * </p>
+        *
+        * @param clazz The class to convert. Must be an enum class.
+        * @return The enum class as a raw type suitable for use with {@link 
EnumSet#allOf(Class)}.
+        * @throws ClassCastException if the class is not an enum class.
+        */
+       @SuppressWarnings("rawtypes")
+       public static Class<? extends Enum> asEnumClass(Class<?> clazz) {
+               return clazz.asSubclass(Enum.class);
+       }
+
        /**
         * Resolves and creates a collection, array, or map containing all 
beans of the element type from the bean store.
         *
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index bdf6998617..7de64f3665 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -1406,8 +1406,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
                var useEnumNames = nn(bc) && bc.isUseEnumNames();
 
                var m = BidiMap.<Object,String>create().unmodifiable();
-               var c = inner().asSubclass(Enum.class);
-               stream(c.getEnumConstants()).forEach(x -> m.add(x, useEnumNames 
? x.name() : x.toString()));
+               stream(asEnumClass(inner()).getEnumConstants()).forEach(x -> 
m.add(x, useEnumNames ? x.name() : x.toString()));
                return m.build();
        }
 
@@ -1430,7 +1429,7 @@ public class ClassMeta<T> extends ClassInfoTyped<T> {
                        } else if (cat.is(CHARSEQ)) {
                                example = "foo";
                        } else if (cat.is(ENUM)) {
-                               Iterator<? extends Enum<?>> i = 
EnumSet.allOf(inner().asSubclass(Enum.class)).iterator();
+                               Iterator<? extends Enum<?>> i = 
EnumSet.allOf(asEnumClass(inner())).iterator();
                                example = i.hasNext() ? 
(beanContext.isUseEnumNames() ? i.next().name() : i.next().toString()) : null;
                        } else if (isAny(float.class, Float.class, 
double.class, Double.class)) {
                                example = "1.0";
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ClassInfo_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ClassInfo_Test.java
index 9eb2be96db..02bf208c0c 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ClassInfo_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ClassInfo_Test.java
@@ -2037,32 +2037,42 @@ public class ClassInfo_Test extends TestBase {
        }
 
        /**
-        * Tests that getPublicMethods() excludes both bridge and synthetic 
methods.
-        * Some methods can be both bridge and synthetic, and they should be 
excluded.
+        * Tests that getPublicMethods() includes bridge and synthetic methods, 
matching Class.getMethods() behavior.
+        * Bridge methods are compiler-generated methods for type erasure in 
generics.
+        * Synthetic methods are compiler-generated methods (e.g., for lambda 
expressions, enum values, etc.).
         */
        @Test
-       void a059d_getPublicMethods_excludesBridgeAndSyntheticMethods() {
+       void a059d_getPublicMethods_includesBridgeAndSyntheticMethods() {
                // Test with ArrayList which implements List and has bridge 
methods
                var arrayListInfo = ClassInfo.of(java.util.ArrayList.class);
                var publicMethods = arrayListInfo.getPublicMethods();
 
-               // Verify no bridge methods are included
+               // Get the corresponding methods from Class.getMethods() for 
comparison
+               var classMethods = java.util.ArrayList.class.getMethods();
+               var classBridgeMethods = 
java.util.stream.Stream.of(classMethods)
+                       .filter(java.lang.reflect.Method::isBridge)
+                       .toList();
+               var classSyntheticMethods = 
java.util.stream.Stream.of(classMethods)
+                       .filter(java.lang.reflect.Method::isSynthetic)
+                       .toList();
+
+               // Verify that getPublicMethods() includes bridge methods 
(matching Class.getMethods())
                var bridgeMethods = publicMethods.stream()
                        .filter(MethodInfo::isBridge)
                        .toList();
-               assertTrue(bridgeMethods.isEmpty(), "getPublicMethods() should 
not include bridge methods. Found: " + bridgeMethods);
+               assertEquals(classBridgeMethods.size(), bridgeMethods.size(), 
+                       "getPublicMethods() should include bridge methods 
matching Class.getMethods(). " +
+                       "Class.getMethods() has " + classBridgeMethods.size() + 
" bridge methods, " +
+                       "getPublicMethods() has " + bridgeMethods.size() + " 
bridge methods.");
 
-               // Verify no synthetic methods are included
+               // Verify that getPublicMethods() includes synthetic methods 
(matching Class.getMethods())
                var syntheticMethods = publicMethods.stream()
                        .filter(MethodInfo::isSynthetic)
                        .toList();
-               assertTrue(syntheticMethods.isEmpty(), "getPublicMethods() 
should not include synthetic methods. Found: " + syntheticMethods);
-
-               // Verify that methods that are both bridge and synthetic are 
excluded
-               var bridgeOrSynthetic = publicMethods.stream()
-                       .filter(m -> m.isBridge() || m.isSynthetic())
-                       .toList();
-               assertTrue(bridgeOrSynthetic.isEmpty(), "getPublicMethods() 
should not include methods that are bridge or synthetic. Found: " + 
bridgeOrSynthetic);
+               assertEquals(classSyntheticMethods.size(), 
syntheticMethods.size(),
+                       "getPublicMethods() should include synthetic methods 
matching Class.getMethods(). " +
+                       "Class.getMethods() has " + 
classSyntheticMethods.size() + " synthetic methods, " +
+                       "getPublicMethods() has " + syntheticMethods.size() + " 
synthetic methods.");
        }
 
        
//====================================================================================================

Reply via email to