Skip to content

Commit 704f064

Browse files
committed
Merge branch '2.11' into 2.12
2 parents 6591716 + abe5d1d commit 704f064

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.math.BigDecimal;
56
import java.math.BigInteger;
@@ -332,33 +333,56 @@ public static String getTypeId(Schema schema) {
332333
* </p>
333334
*/
334335
public static String getFullName(Schema schema) {
335-
switch (schema.getType()) {
336+
final Schema.Type type = schema.getType();
337+
switch (type) {
336338
case RECORD:
337339
case ENUM:
338340
case FIXED:
339-
String namespace = schema.getNamespace();
340-
String name = schema.getName();
341+
final String namespace = schema.getNamespace();
342+
final String name = schema.getName();
343+
344+
// Handle (presumed) common case
341345
if (namespace == null) {
342-
return schema.getName();
346+
return name;
343347
}
344-
if (namespace.endsWith("$")) {
348+
final int len = namespace.length();
349+
if (namespace.charAt(len-1) == '$') {
345350
return namespace + name;
346351
}
347-
StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
348-
// 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
349-
// to support differences between avro-lib 1.8 and 1.9...
350-
// Check if this is a nested class
351-
String nestedClassName = sb.append(namespace).append('$').append(name).toString();
352-
try {
353-
Class.forName(nestedClassName);
354-
return nestedClassName;
355-
} catch (ClassNotFoundException e) {
356-
// Could not find a nested class, must be a regular class
357-
sb.setLength(0);
358-
return sb.append(namespace).append('.').append(name).toString();
359-
}
360-
default:
361-
return schema.getType().getName();
352+
return _findFullName(namespace, name);
353+
354+
default:
355+
return type.getName();
356+
}
357+
}
358+
359+
private static String _findFullName(final String namespace, final String name) {
360+
final String cacheKey = namespace + "." + name;
361+
String schemaName = SCHEMA_NAME_CACHE.get(cacheKey);
362+
363+
if (schemaName == null) {
364+
schemaName = _resolveFullName(namespace, name);
365+
SCHEMA_NAME_CACHE.put(cacheKey, schemaName);
366+
}
367+
return schemaName;
368+
}
369+
370+
private static String _resolveFullName(final String namespace, final String name) {
371+
StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
372+
373+
// 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
374+
// to support differences between avro-lib 1.8 and 1.9...
375+
// Check if this is a nested class
376+
final String nestedClassName = sb.append(namespace).append('$').append(name).toString();
377+
try {
378+
Class.forName(nestedClassName);
379+
380+
return nestedClassName;
381+
} catch (ClassNotFoundException e) {
382+
// Could not find a nested class, must be a regular class
383+
sb.setLength(0);
384+
385+
return sb.append(namespace).append('.').append(name).toString();
362386
}
363387
}
364388

@@ -414,4 +438,7 @@ public static JsonNode parseDefaultValue(String defaultValue) throws JsonMapping
414438
throw new JsonMappingException(null, "Failed to parse default value", e);
415439
}
416440
}
441+
442+
// @since 2.11.3
443+
private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(80, 800);
417444
}

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)