Skip to content

Commit abe5d1d

Browse files
committed
Add release notes wrt #219, minor reorg
1 parent 80b8a19 commit abe5d1d

File tree

4 files changed

+47
-38
lines changed

4 files changed

+47
-38
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/AvroReaderFactory.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ public ScalarDecoder createScalarValueDecoder(Schema type)
6666
case FLOAT:
6767
return READER_FLOAT;
6868
case INT:
69-
if (AvroSchemaHelper.getTypeId(type) != null) {
70-
return new IntReader(AvroSchemaHelper.getTypeId(type));
69+
{
70+
final String typeId = AvroSchemaHelper.getTypeId(type);
71+
return (typeId != null) ? new IntReader(typeId) : READER_INT;
7172
}
72-
return READER_INT;
7373
case LONG:
7474
return READER_LONG;
7575
case NULL:
7676
return READER_NULL;
7777
case STRING:
78-
if (AvroSchemaHelper.getTypeId(type) != null) {
79-
return new StringReader(AvroSchemaHelper.getTypeId(type));
78+
{
79+
final String typeId = AvroSchemaHelper.getTypeId(type);
80+
return (typeId != null) ? new StringReader(typeId) : READER_STRING;
8081
}
81-
return READER_STRING;
8282
case UNION:
8383
/* Union is a "scalar union" if all the alternative types
8484
* are scalar. One common type is that of "nullable" one,

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java

+34-32
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
public abstract class AvroSchemaHelper
2727
{
28-
private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(16, 1024);
29-
3028
/**
3129
* Dedicated mapper for handling default values (String &lt;-&gt; JsonNode &lt;-&gt; Object)
3230
*
@@ -334,46 +332,47 @@ public static String getTypeId(Schema schema) {
334332
* </p>
335333
*/
336334
public static String getFullName(Schema schema) {
337-
switch (schema.getType()) {
338-
case RECORD:
339-
case ENUM:
340-
case FIXED:
341-
String namespace = schema.getNamespace();
342-
String name = schema.getName();
343-
String key = namespace + "." + name;
344-
String schemaName = SCHEMA_NAME_CACHE.get(key);
345-
346-
if (schemaName == null) {
347-
schemaName = resolveFullName(schema);
348-
SCHEMA_NAME_CACHE.put(key, schemaName);
349-
}
350-
351-
return schemaName;
352-
353-
default:
354-
return schema.getType().getName();
355-
}
356-
}
335+
final Schema.Type type = schema.getType();
336+
switch (type) {
337+
case RECORD:
338+
case ENUM:
339+
case FIXED:
340+
final String namespace = schema.getNamespace();
341+
final String name = schema.getName();
357342

358-
private static String resolveFullName(Schema schema) {
359-
String namespace = schema.getNamespace();
360-
String name = schema.getName();
343+
// Handle (presumed) common case
344+
if (namespace == null) {
345+
return name;
346+
}
347+
final int len = namespace.length();
348+
if (namespace.charAt(len-1) == '$') {
349+
return namespace + name;
350+
}
351+
return _findFullName(namespace, name);
361352

362-
if (namespace == null) {
363-
return schema.getName();
353+
default:
354+
return type.getName();
364355
}
356+
}
365357

366-
if (namespace.endsWith("$")) {
367-
return namespace + name;
368-
}
358+
private static String _findFullName(final String namespace, final String name) {
359+
final String cacheKey = namespace + "." + name;
360+
String schemaName = SCHEMA_NAME_CACHE.get(cacheKey);
369361

362+
if (schemaName == null) {
363+
schemaName = _resolveFullName(namespace, name);
364+
SCHEMA_NAME_CACHE.put(cacheKey, schemaName);
365+
}
366+
return schemaName;
367+
}
368+
369+
private static String _resolveFullName(final String namespace, final String name) {
370370
StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
371371

372372
// 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
373373
// to support differences between avro-lib 1.8 and 1.9...
374374
// Check if this is a nested class
375-
String nestedClassName = sb.append(namespace).append('$').append(name).toString();
376-
375+
final String nestedClassName = sb.append(namespace).append('$').append(name).toString();
377376
try {
378377
Class.forName(nestedClassName);
379378

@@ -438,4 +437,7 @@ public static JsonNode parseDefaultValue(String defaultValue) throws JsonMapping
438437
throw new JsonMappingException(null, "Failed to parse default value", e);
439438
}
440439
}
440+
441+
// @since 2.11.3
442+
private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(80, 800);
441443
}

release-notes/CREDITS-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Marcos Passos (marcospassos@github)
108108
(2.10.5)
109109
* Contributed fix for #216: (avro) Avro null deserialization
110110
(2.11.2)
111+
* Contributed #219: Cache record names to avoid hitting class loader
112+
(2.11.3)
111113

112114
John (iziamos@github)
113115
* Reported, suggested fix for #178: Fix issue wit input offsets when parsing CBOR from `InputStream`

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Project: jackson-datatypes-binaryModules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11+
2.11.3 (not yet released)
12+
13+
#219: Cache record names to avoid hitting class loader
14+
(contributed by Marcos P)
15+
1116
2.11.2 (02-Aug-2020)
1217

1318
#216: (avro) Avro null deserialization

0 commit comments

Comments
 (0)