From 30c0bdbad3699f052e327566414a641ac22c07aa Mon Sep 17 00:00:00 2001 From: Tobias Gierke Date: Fri, 13 Oct 2023 18:45:09 +0200 Subject: [PATCH] Fix support of lambda objects for Java 21 and above. Closes #349. --- xstream-distribution/src/content/changes.html | 1 + .../com/thoughtworks/xstream/core/util/Types.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xstream-distribution/src/content/changes.html b/xstream-distribution/src/content/changes.html index fd226029f..65e08e4a3 100644 --- a/xstream-distribution/src/content/changes.html +++ b/xstream-distribution/src/content/changes.html @@ -115,6 +115,7 @@

Minor changes

  • GHPR:#331, GHI:#326: Fix handling of empty java.util.concurrent.atomic.AtomicReference (by Alex Blekhman of Atlassian).
  • GHPR:#334: Fix remaining buffer size calculation in QuickWriter (by Higuchi Yuta).
  • GHI:#342: Optimize internal handling of children in DomReader avoiding O(n²) access times for siblings (by Shiang-Yun Yang).
  • +
  • GHPR:#349: Fix support of lambda objects for Java 21 and above (Tobias Gierke).
  • GHI:#359: Add KEYS file with public keys to verify signed artifacts.
  • Detect input manipulation in c.t.x.io.binary.BinaryStreamReader.
  • diff --git a/xstream/src/java/com/thoughtworks/xstream/core/util/Types.java b/xstream/src/java/com/thoughtworks/xstream/core/util/Types.java index 5168be7a3..ad1c7e4aa 100644 --- a/xstream/src/java/com/thoughtworks/xstream/core/util/Types.java +++ b/xstream/src/java/com/thoughtworks/xstream/core/util/Types.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 XStream Committers. + * Copyright (C) 2015, 2024 XStream Committers. * All rights reserved. * * Created on 17. January 2015 by Joerg Schaible @@ -16,10 +16,13 @@ * @since 1.4.8 */ public class Types { - private static final Pattern lambdaPattern = Pattern.compile(".*\\$\\$Lambda\\$[0-9]+/.*"); + private static final Pattern lambdaPattern = Pattern.compile(".*\\$\\$Lambda(?:\\$[0-9]+|)/.*"); public static final boolean isLambdaType(final Class type) { - return type != null && type.isSynthetic() && lambdaPattern.matcher(type.getSimpleName()).matches(); + if (type != null && type.isSynthetic()) { + final String typeName = type.getSimpleName(); + return lambdaPattern.matcher(typeName).matches(); + } + return false; } - }