Skip to content

Commit c1c6d0a

Browse files
committed
Merge branch '2.12'
2 parents c26d209 + 704f064 commit c1c6d0a

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

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

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.avro.schema;
22

3+
import com.fasterxml.jackson.databind.util.LRUMap;
34
import java.io.File;
45
import java.io.IOException;
56
import java.math.BigDecimal;
@@ -320,33 +321,56 @@ public static String getTypeId(Schema schema) {
320321
* </p>
321322
*/
322323
public static String getFullName(Schema schema) {
323-
switch (schema.getType()) {
324+
final Schema.Type type = schema.getType();
325+
switch (type) {
324326
case RECORD:
325327
case ENUM:
326328
case FIXED:
327-
String namespace = schema.getNamespace();
328-
String name = schema.getName();
329+
final String namespace = schema.getNamespace();
330+
final String name = schema.getName();
331+
332+
// Handle (presumed) common case
329333
if (namespace == null) {
330-
return schema.getName();
334+
return name;
331335
}
332-
if (namespace.endsWith("$")) {
336+
final int len = namespace.length();
337+
if (namespace.charAt(len-1) == '$') {
333338
return namespace + name;
334339
}
335-
StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
336-
// 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
337-
// to support differences between avro-lib 1.8 and 1.9...
338-
// Check if this is a nested class
339-
String nestedClassName = sb.append(namespace).append('$').append(name).toString();
340-
try {
341-
Class.forName(nestedClassName);
342-
return nestedClassName;
343-
} catch (ClassNotFoundException e) {
344-
// Could not find a nested class, must be a regular class
345-
sb.setLength(0);
346-
return sb.append(namespace).append('.').append(name).toString();
347-
}
348-
default:
349-
return schema.getType().getName();
340+
return _findFullName(namespace, name);
341+
342+
default:
343+
return type.getName();
344+
}
345+
}
346+
347+
private static String _findFullName(final String namespace, final String name) {
348+
final String cacheKey = namespace + "." + name;
349+
String schemaName = SCHEMA_NAME_CACHE.get(cacheKey);
350+
351+
if (schemaName == null) {
352+
schemaName = _resolveFullName(namespace, name);
353+
SCHEMA_NAME_CACHE.put(cacheKey, schemaName);
354+
}
355+
return schemaName;
356+
}
357+
358+
private static String _resolveFullName(final String namespace, final String name) {
359+
StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
360+
361+
// 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
362+
// to support differences between avro-lib 1.8 and 1.9...
363+
// Check if this is a nested class
364+
final String nestedClassName = sb.append(namespace).append('$').append(name).toString();
365+
try {
366+
Class.forName(nestedClassName);
367+
368+
return nestedClassName;
369+
} catch (ClassNotFoundException e) {
370+
// Could not find a nested class, must be a regular class
371+
sb.setLength(0);
372+
373+
return sb.append(namespace).append('.').append(name).toString();
350374
}
351375
}
352376

@@ -391,4 +415,7 @@ public static JsonNode parseDefaultValue(String defaultValue) throws JsonMapping
391415
throw new JsonMappingException(null, "Failed to parse default value", e);
392416
}
393417
}
418+
419+
// @since 2.11.3
420+
private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(80, 800);
394421
}

release-notes/CREDITS-2.x

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Project: jackson-datatypes-binaryModules:
1616
(contributed by Michael L)
1717
- Add Gradle Module Metadata (https://blog.gradle.org/alignment-with-gradle-module-metadata)
1818

19+
2.11.3 (not yet released)
20+
21+
#219: Cache record names to avoid hitting class loader
22+
(contributed by Marcos P)
23+
1924
2.11.2 (02-Aug-2020)
2025

2126
#216: (avro) Avro null deserialization

0 commit comments

Comments
 (0)