diff --git a/blackbird/src/main/java/tools/jackson/module/blackbird/util/ReflectionHack.java b/blackbird/src/main/java/tools/jackson/module/blackbird/util/ReflectionHack.java index cc8575f6..2817f384 100644 --- a/blackbird/src/main/java/tools/jackson/module/blackbird/util/ReflectionHack.java +++ b/blackbird/src/main/java/tools/jackson/module/blackbird/util/ReflectionHack.java @@ -53,7 +53,13 @@ private static MethodHandle init() { } public static Lookup privateLookupIn(Class lookup, Lookup orig) { - return Unchecked.supplier(() -> (Lookup) FACTORY.invokeExact(lookup, orig)).get(); + try { + return (Lookup) FACTORY.invokeExact(lookup, orig); + } catch (ReflectiveOperationException e) { + return orig; + } catch (Throwable t) { + throw Sneaky.throwAnyway(t); + } } } diff --git a/blackbird/src/test/java/tools/jackson/module/blackbird/TestAccessFallback.java b/blackbird/src/test/java/tools/jackson/module/blackbird/TestAccessFallback.java index c2069da6..8942dec1 100644 --- a/blackbird/src/test/java/tools/jackson/module/blackbird/TestAccessFallback.java +++ b/blackbird/src/test/java/tools/jackson/module/blackbird/TestAccessFallback.java @@ -1,5 +1,7 @@ package tools.jackson.module.blackbird; +import java.lang.reflect.Proxy; + import tools.jackson.databind.ObjectMapper; public class TestAccessFallback extends BlackbirdTestBase @@ -69,4 +71,19 @@ public void testDeserializeAccess() throws Exception MyBean bean2 = abMapper.readValue(BEAN_JSON, MyBean.class); assertEquals("a", bean2.getE()); } + + public void testProxyAccessIssue181() throws Exception { + ObjectMapper om = newObjectMapper(); + String val = om.writeValueAsString(Proxy.newProxyInstance(TestAccessFallback.class.getClassLoader(), new Class[] { Beany.class }, (p, m, a) -> { + if (m.getName().equals("getA")) { + return 42; + } + return null; + })); + assertEquals("{\"a\":42}", val); + } + + public interface Beany { + int getA(); + } } diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 384c5df0..4626fdef 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -81,6 +81,7 @@ Steven Schlansker (stevenschlansker@github) (2.12.0) * Fixed #141: Blackbird fails to deserialize varargs array (2.13.0) +... and many, many more (esp. to Afterburner/Blackbird projects) Marc Magon (GedMarc@github) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 5e90d222..263c00e4 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -23,6 +23,9 @@ Active maintainers: 2.16.0 (not yet released) +#181: BlackBird proxy object error in Java 17 + (fix by Steven S) + #209: Add guice7 (jakarta.inject) module (contributed by Joe B)