Skip to content

Commit

Permalink
Fix #131
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 23, 2021
1 parent dba6a41 commit 71d4c70
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ public static boolean canAddClassInPackageOf(Class<?> cls)
return false;
}
String pname = beanPackage.getName();
/* 14-Aug-2014, tatu: java.* we do not want to touch, but
* javax is bit trickier. For now let's
*/
// 14-Aug-2014, tatu: java.* we do not want to touch, but
// javax is bit trickier.
if (pname.startsWith("java.")
|| pname.startsWith("javax.security.")) {
|| pname.startsWith("javax.security.")
// 23-Apr-2021, tatu: [modules-base#131] "sun.misc"
// problematic too
|| pname.startsWith("sun.misc")
) {
return false;
}
}
return true;
}

/**
* @param className Interface or abstract class that class to load should extend or
* implement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fasterxml.jackson.module.afterburner.misc;

import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;

public class PreventJDKTypeAccessTest extends AfterburnerTestBase
{
private final ObjectMapper MAPPER = newObjectMapper();
private final ObjectMapper VANILLA_MAPPER = newVanillaJSONMapper();

public void testJDKThreadroundTrip() throws Exception
{
final Object input = Thread.currentThread();
final String json1 = VANILLA_MAPPER.writeValueAsString(input);
final String json2 = MAPPER.writeValueAsString(input);

Map<?,?> map1 = VANILLA_MAPPER.readValue(json1, Map.class);
Map<?,?> map2 = MAPPER.readValue(json2, Map.class);

assertEquals(map1.keySet(), map2.keySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public BlackbirdModule(Function<Class<?>, MethodHandles.Lookup> lookups) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.fasterxml.jackson.module.blackbird.misc;

import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;

public class PreventJDKTypeAccessTest extends BlackbirdTestBase
{
private final ObjectMapper MAPPER = newObjectMapper();
private final ObjectMapper VANILLA_MAPPER = newVanillaJSONMapper();

public void testJDKThreadroundTrip() throws Exception
{
final Object input = Thread.currentThread();
final String json1 = VANILLA_MAPPER.writeValueAsString(input);
final String json2 = MAPPER.writeValueAsString(input);

Map<?,?> map1 = VANILLA_MAPPER.readValue(json1, Map.class);
Map<?,?> map2 = MAPPER.readValue(json2, Map.class);

assertEquals(map1.keySet(), map2.keySet());
}
}
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.12.4 (not yet released

#131: Failing to serialize `Thread` returned by `Thread.currentThread()` when Afterburner
or Blackbird registered
(reported by Liudapeng@github)

2.12.3 (12-Apr-2021)
2.12.2 (03-Mar-2021)

Expand Down

0 comments on commit 71d4c70

Please sign in to comment.