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 2025/11/19 15:14:27 UTC
(commons-lang) branch master updated (8edc751f6 -> f788ce2b5)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
from 8edc751f6 ClassUtils now throws IllegalArgumentException if a class name length is greater than 65,535
new 19adcd792 Sort members
new f788ce2b5 Javadoc
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:
.../java/org/apache/commons/lang3/ClassUtils.java | 92 ++++++++++-------
.../org/apache/commons/lang3/time/StopWatch.java | 112 ++++++++++-----------
.../org/apache/commons/lang3/ClassUtilsTest.java | 4 +-
.../apache/commons/lang3/time/StopWatchTest.java | 60 +++++------
4 files changed, 144 insertions(+), 124 deletions(-)
(commons-lang) 01/02: Sort members
Posted by gg...@apache.org.
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-lang.git
commit 19adcd792fb514e741cabdeda87e41f405fed268
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Nov 19 10:09:26 2025 -0500
Sort members
---
.../java/org/apache/commons/lang3/ClassUtils.java | 72 ++++++-------
.../org/apache/commons/lang3/time/StopWatch.java | 112 ++++++++++-----------
.../org/apache/commons/lang3/ClassUtilsTest.java | 4 +-
.../apache/commons/lang3/time/StopWatchTest.java | 60 +++++------
4 files changed, 124 insertions(+), 124 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index f6185e9d9..6e8af9d9c 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -48,6 +48,20 @@
*/
public class ClassUtils {
+ /**
+ * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}.
+ *
+ * @since 3.2
+ */
+ public enum Interfaces {
+
+ /** Includes interfaces. */
+ INCLUDE,
+
+ /** Excludes interfaces. */
+ EXCLUDE
+ }
+
/**
* The JLS-specified maximum class name length {@value}.
*
@@ -68,20 +82,6 @@ public class ClassUtils {
*/
private static final int MAX_JVM_ARRAY_DIMENSION = 255;
- /**
- * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}.
- *
- * @since 3.2
- */
- public enum Interfaces {
-
- /** Includes interfaces. */
- INCLUDE,
-
- /** Excludes interfaces. */
- EXCLUDE
- }
-
/**
* The maximum number of array dimensions.
*/
@@ -1535,6 +1535,28 @@ public static Class<?> primitiveToWrapper(final Class<?> cls) {
return cls != null && cls.isPrimitive() ? PRIMITIVE_WRAPPER_MAP.get(cls) : cls;
}
+ /**
+ * Converts an array of {@link Object} in to an array of {@link Class} objects. If any of these objects is null, a null element will be inserted into the
+ * array.
+ *
+ * <p>
+ * This method returns {@code null} for a {@code null} input array.
+ * </p>
+ *
+ * @param array an {@link Object} array.
+ * @return a {@link Class} array, {@code null} if null array input.
+ * @since 2.4
+ */
+ public static Class<?>[] toClass(final Object... array) {
+ if (array == null) {
+ return null;
+ }
+ if (array.length == 0) {
+ return ArrayUtils.EMPTY_CLASS_ARRAY;
+ }
+ return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass());
+ }
+
/**
* Converts and cleans up a class name to a JLS style class name.
*
@@ -1596,28 +1618,6 @@ private static String toCleanName(final String className) {
return canonicalName;
}
- /**
- * Converts an array of {@link Object} in to an array of {@link Class} objects. If any of these objects is null, a null element will be inserted into the
- * array.
- *
- * <p>
- * This method returns {@code null} for a {@code null} input array.
- * </p>
- *
- * @param array an {@link Object} array.
- * @return a {@link Class} array, {@code null} if null array input.
- * @since 2.4
- */
- public static Class<?>[] toClass(final Object... array) {
- if (array == null) {
- return null;
- }
- if (array.length == 0) {
- return ArrayUtils.EMPTY_CLASS_ARRAY;
- }
- return ArrayUtils.setAll(new Class[array.length], i -> array[i] == null ? null : array[i].getClass());
- }
-
/**
* Decides if the part that was just copied to its destination location in the work array can be kept as it was copied
* or must be abbreviated. It must be kept when the part is the last one, which is the simple name of the class. In this
diff --git a/src/main/java/org/apache/commons/lang3/time/StopWatch.java b/src/main/java/org/apache/commons/lang3/time/StopWatch.java
index 4a8823f4f..72b072069 100644
--- a/src/main/java/org/apache/commons/lang3/time/StopWatch.java
+++ b/src/main/java/org/apache/commons/lang3/time/StopWatch.java
@@ -73,6 +73,52 @@
*/
public class StopWatch {
+ /**
+ * Stores a split as a label and duration.
+ *
+ * @since 3.20.0
+ */
+ public static final class Split extends ImmutablePair<String, Duration> {
+
+ /**
+ * Constructs a Split object with label and duration.
+ *
+ * @param label Label for this split.
+ * @param duration Duration for this split.
+ */
+ public Split(String label, Duration duration) {
+ super(label, duration);
+ }
+
+ /**
+ * Gets the duration of this split.
+ *
+ * @return The duration of this split..
+ */
+ public Duration getDuration() {
+ return getRight();
+ }
+
+ /**
+ * Gets the label of this split.
+ *
+ * @return The label of this split.
+ */
+ public String getLabel() {
+ return getLeft();
+ }
+
+ /**
+ * Converts this instance to a string.
+ *
+ * @return this instance to a string.
+ */
+ @Override
+ public String toString() {
+ return String.format("Split [%s, %s])", getLabel(), getDuration());
+ }
+ }
+
/**
* Enumeration type which indicates the split status of a StopWatch.
*/
@@ -335,16 +381,6 @@ public String getMessage() {
return message;
}
- /**
- * Gets the split list.
- *
- * @return the list of splits.
- * @since 3.20.0
- */
- public List<Split> getSplits() {
- return Collections.unmodifiableList(splits);
- }
-
/**
* Gets the <em>elapsed</em> time in nanoseconds.
*
@@ -404,6 +440,16 @@ public long getSplitNanoTime() {
return splits.get(splits.size() - 1).getRight().toNanos();
}
+ /**
+ * Gets the split list.
+ *
+ * @return the list of splits.
+ * @since 3.20.0
+ */
+ public List<Split> getSplits() {
+ return Collections.unmodifiableList(splits);
+ }
+
/**
* Gets the split time on this StopWatch.
*
@@ -790,50 +836,4 @@ public void unsplit() {
splits.remove(splits.size() - 1);
}
- /**
- * Stores a split as a label and duration.
- *
- * @since 3.20.0
- */
- public static final class Split extends ImmutablePair<String, Duration> {
-
- /**
- * Constructs a Split object with label and duration.
- *
- * @param label Label for this split.
- * @param duration Duration for this split.
- */
- public Split(String label, Duration duration) {
- super(label, duration);
- }
-
- /**
- * Gets the label of this split.
- *
- * @return The label of this split.
- */
- public String getLabel() {
- return getLeft();
- }
-
- /**
- * Gets the duration of this split.
- *
- * @return The duration of this split..
- */
- public Duration getDuration() {
- return getRight();
- }
-
- /**
- * Converts this instance to a string.
- *
- * @return this instance to a string.
- */
- @Override
- public String toString() {
- return String.format("Split [%s, %s])", getLabel(), getDuration());
- }
- }
-
}
diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
index 96ce5cdad..f4cdc9c47 100644
--- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
@@ -59,8 +59,6 @@
@SuppressWarnings("boxing") // JUnit4 does not support primitive equality testing apart from long
class ClassUtilsTest extends AbstractLangTest {
- private static final int MAX_ARRAY_DIMENSIONS = 255;
-
private static class CX implements IB, IA, IE {
// empty
}
@@ -100,6 +98,8 @@ private static final class DeeplyNested {
}
}
+ private static final int MAX_ARRAY_DIMENSIONS = 255;
+
private static final String OBJECT_CANONICAL_NAME = "java.lang.Object";
private void assertGetClassReturnsClass(final Class<?> c) throws Exception {
diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
index d365dceac..bffb29acb 100644
--- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
@@ -392,6 +392,36 @@ void testSplit() throws InterruptedException {
assertTrue(totalDuration.toMillis() >= sleepMillisX3);
}
+ @Test
+ void testSplitsWithStringLabels() {
+ final StopWatch watch = new StopWatch();
+ final String firstLabel = "one";
+ final String secondLabel = "two";
+ final String thirdLabel = "three";
+ watch.start();
+ // starting splits
+ watch.split(firstLabel);
+ watch.split(secondLabel);
+ watch.split(thirdLabel);
+ watch.stop();
+ // getting splits
+ final List<StopWatch.Split> splits = watch.getSplits();
+ // check size
+ assertEquals(3, splits.size());
+ // check labels
+ assertEquals(firstLabel, splits.get(0).getLabel());
+ assertEquals(secondLabel, splits.get(1).getLabel());
+ assertEquals(thirdLabel, splits.get(2).getLabel());
+ // check time in nanos
+ assertTrue(splits.get(0).getDuration().toNanos() > 0);
+ assertTrue(splits.get(1).getDuration().toNanos() > 0);
+ assertTrue(splits.get(2).getDuration().toNanos() > 0);
+ // We can only unsplit once
+ watch.unsplit();
+ assertEquals(2, watch.getSplits().size());
+ assertThrows(IllegalStateException.class, watch::unsplit);
+ }
+
@Test
void testStatic() {
final StopWatch watch = StopWatch.createStarted();
@@ -522,36 +552,6 @@ void testToStringWithMessage() throws InterruptedException {
assertEquals(SPLIT_CLOCK_STR_LEN + MESSAGE.length() + 1, splitStr.length(), "Formatted split string not the correct length");
}
- @Test
- void testSplitsWithStringLabels() {
- final StopWatch watch = new StopWatch();
- final String firstLabel = "one";
- final String secondLabel = "two";
- final String thirdLabel = "three";
- watch.start();
- // starting splits
- watch.split(firstLabel);
- watch.split(secondLabel);
- watch.split(thirdLabel);
- watch.stop();
- // getting splits
- final List<StopWatch.Split> splits = watch.getSplits();
- // check size
- assertEquals(3, splits.size());
- // check labels
- assertEquals(firstLabel, splits.get(0).getLabel());
- assertEquals(secondLabel, splits.get(1).getLabel());
- assertEquals(thirdLabel, splits.get(2).getLabel());
- // check time in nanos
- assertTrue(splits.get(0).getDuration().toNanos() > 0);
- assertTrue(splits.get(1).getDuration().toNanos() > 0);
- assertTrue(splits.get(2).getDuration().toNanos() > 0);
- // We can only unsplit once
- watch.unsplit();
- assertEquals(2, watch.getSplits().size());
- assertThrows(IllegalStateException.class, watch::unsplit);
- }
-
private int throwIOException() throws IOException {
throw new IOException("A");
}
(commons-lang) 02/02: Javadoc
Posted by gg...@apache.org.
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-lang.git
commit f788ce2b5ecadc09c304e94ab2a7fa17239f9bd9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Nov 19 10:14:20 2025 -0500
Javadoc
---
.../java/org/apache/commons/lang3/ClassUtils.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index 6e8af9d9c..9c7195082 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -539,6 +539,10 @@ private static String getCanonicalName(final String name) {
* Gets the (initialized) class represented by {@code className} using the {@code classLoader}. This implementation
* supports the syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}",
* "{@code [Ljava.util.Map.Entry;}", and "{@code [Ljava.util.Map$Entry;}".
+ * <p>
+ * The provided class name is normalized by removing all whitespace. This is especially helpful when handling XML element values in which whitespace has not
+ * been collapsed.
+ * </p>
*
* @param classLoader the class loader to use to load the class.
* @param className the class name.
@@ -560,6 +564,10 @@ public static Class<?> getClass(final ClassLoader classLoader, final String clas
* Gets the class represented by {@code className} using the {@code classLoader}. This implementation supports the
* syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}", "{@code [Ljava.util.Map.Entry;}", and
* "{@code [Ljava.util.Map$Entry;}".
+ * <p>
+ * The provided class name is normalized by removing all whitespace. This is especially helpful when handling XML element values in which whitespace has not
+ * been collapsed.
+ * </p>
*
* @param classLoader the class loader to use to load the class.
* @param className the class name.
@@ -596,6 +604,10 @@ public static Class<?> getClass(final ClassLoader classLoader, final String clas
* Gets the (initialized) class represented by {@code className} using the current thread's context class loader.
* This implementation supports the syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}",
* "{@code [Ljava.util.Map.Entry;}", and "{@code [Ljava.util.Map$Entry;}".
+ * <p>
+ * The provided class name is normalized by removing all whitespace. This is especially helpful when handling XML element values in which whitespace has not
+ * been collapsed.
+ * </p>
*
* @param className the class name
* @return the class represented by {@code className} using the current thread's context class loader
@@ -616,6 +628,10 @@ public static Class<?> getClass(final String className) throws ClassNotFoundExce
* Gets the class represented by {@code className} using the current thread's context class loader. This
* implementation supports the syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}",
* "{@code [Ljava.util.Map.Entry;}", and "{@code [Ljava.util.Map$Entry;}".
+ * <p>
+ * The provided class name is normalized by removing all whitespace. This is especially helpful when handling XML element values in which whitespace has not
+ * been collapsed.
+ * </p>
*
* @param className the class name.
* @param initialize whether the class must be initialized.
@@ -1559,6 +1575,10 @@ public static Class<?>[] toClass(final Object... array) {
/**
* Converts and cleans up a class name to a JLS style class name.
+ * <p>
+ * The provided class name is normalized by removing all whitespace. This is especially helpful when handling XML element values in which whitespace has not
+ * been collapsed.
+ * </p>
*
* @param className the class name.
* @return the converted name.