Skip to content

Commit 71d4c70

Browse files
committed
Fix #131
1 parent dba6a41 commit 71d4c70

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/util/MyClassLoader.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ public static boolean canAddClassInPackageOf(Class<?> cls)
4848
return false;
4949
}
5050
String pname = beanPackage.getName();
51-
/* 14-Aug-2014, tatu: java.* we do not want to touch, but
52-
* javax is bit trickier. For now let's
53-
*/
51+
// 14-Aug-2014, tatu: java.* we do not want to touch, but
52+
// javax is bit trickier.
5453
if (pname.startsWith("java.")
55-
|| pname.startsWith("javax.security.")) {
54+
|| pname.startsWith("javax.security.")
55+
// 23-Apr-2021, tatu: [modules-base#131] "sun.misc"
56+
// problematic too
57+
|| pname.startsWith("sun.misc")
58+
) {
5659
return false;
5760
}
5861
}
5962
return true;
6063
}
61-
64+
6265
/**
6366
* @param className Interface or abstract class that class to load should extend or
6467
* implement
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fasterxml.jackson.module.afterburner.misc;
2+
3+
import java.util.Map;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
7+
8+
public class PreventJDKTypeAccessTest extends AfterburnerTestBase
9+
{
10+
private final ObjectMapper MAPPER = newObjectMapper();
11+
private final ObjectMapper VANILLA_MAPPER = newVanillaJSONMapper();
12+
13+
public void testJDKThreadroundTrip() throws Exception
14+
{
15+
final Object input = Thread.currentThread();
16+
final String json1 = VANILLA_MAPPER.writeValueAsString(input);
17+
final String json2 = MAPPER.writeValueAsString(input);
18+
19+
Map<?,?> map1 = VANILLA_MAPPER.readValue(json1, Map.class);
20+
Map<?,?> map2 = MAPPER.readValue(json2, Map.class);
21+
22+
assertEquals(map1.keySet(), map2.keySet());
23+
}
24+
}

blackbird/src/main/java/com/fasterxml/jackson/module/blackbird/BlackbirdModule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ public BlackbirdModule(Function<Class<?>, MethodHandles.Lookup> lookups) {
2323
}
2424

2525
public BlackbirdModule(Supplier<MethodHandles.Lookup> lookup) {
26-
this(c -> c.getName().startsWith("java") ? null : lookup.get());
26+
this(c -> {
27+
final String className = c.getName();
28+
return (className.startsWith("java.")
29+
// 23-Apr-2021, tatu: [modules-base#131] "sun.misc" problematic too
30+
|| className.startsWith("sun.misc."))
31+
? null : lookup.get();
32+
});
2733
}
2834

2935
@Override
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fasterxml.jackson.module.blackbird.misc;
2+
3+
import java.util.Map;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;
7+
8+
public class PreventJDKTypeAccessTest extends BlackbirdTestBase
9+
{
10+
private final ObjectMapper MAPPER = newObjectMapper();
11+
private final ObjectMapper VANILLA_MAPPER = newVanillaJSONMapper();
12+
13+
public void testJDKThreadroundTrip() throws Exception
14+
{
15+
final Object input = Thread.currentThread();
16+
final String json1 = VANILLA_MAPPER.writeValueAsString(input);
17+
final String json2 = MAPPER.writeValueAsString(input);
18+
19+
Map<?,?> map1 = VANILLA_MAPPER.readValue(json1, Map.class);
20+
Map<?,?> map2 = MAPPER.readValue(json2, Map.class);
21+
22+
assertEquals(map1.keySet(), map2.keySet());
23+
}
24+
}

release-notes/VERSION-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Modules:
1212
=== Releases ===
1313
------------------------------------------------------------------------
1414

15+
2.12.4 (not yet released
16+
17+
#131: Failing to serialize `Thread` returned by `Thread.currentThread()` when Afterburner
18+
or Blackbird registered
19+
(reported by Liudapeng@github)
20+
1521
2.12.3 (12-Apr-2021)
1622
2.12.2 (03-Mar-2021)
1723

0 commit comments

Comments
 (0)