Skip to content

Commit 7ac4800

Browse files
authored
AVRO-4123: Parsed named schemas always empty (#3361)
* AVRO-4123: fix missing parsed schemas * AVRO-4123: Remove unnecessary private method * AVRO-4123: Do not use List.getFirst() yet * AVRO-4123: Fix tests for recent JDKs Recent JDKs alter the requirements for using a security manager. This affects Hadoop code. Also, misplaced javadoc affects tests. When AVRO-4126 is merged, the change to TestSpecificCompiler.java can be reverted.
1 parent bd28a95 commit 7ac4800

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

lang/java/avro/src/main/java/org/apache/avro/ParseContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.avro.util.Schemas;
2222

2323
import java.util.ArrayList;
24-
import java.util.Collection;
2524
import java.util.EnumSet;
2625
import java.util.HashMap;
2726
import java.util.LinkedHashMap;
@@ -253,7 +252,7 @@ public void commit() {
253252
}
254253

255254
public SchemaParser.ParseResult commit(Schema mainSchema) {
256-
Collection<Schema> parsedNamedSchemas = newSchemas.values();
255+
List<Schema> parsedNamedSchemas = new ArrayList<>(newSchemas.values());
257256
SchemaParser.ParseResult parseResult = new SchemaParser.ParseResult() {
258257
@Override
259258
public Schema mainSchema() {

lang/java/avro/src/test/java/org/apache/avro/TestSchemaParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.charset.StandardCharsets;
2828
import java.nio.file.Files;
2929
import java.nio.file.Path;
30+
import java.util.List;
3031

3132
import static java.util.Collections.singletonList;
3233
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -35,7 +36,7 @@
3536

3637
class TestSchemaParser {
3738
private static final Schema SCHEMA_REAL = Schema.createFixed("Real", null, "tests", 42);
38-
private static final String SCHEMA_JSON = SCHEMA_REAL.toString(false);
39+
private static final String SCHEMA_JSON = SchemaFormatter.getInstance("json").format(SCHEMA_REAL);
3940
private static final Charset[] UTF_CHARSETS = { StandardCharsets.UTF_8, StandardCharsets.UTF_16LE,
4041
StandardCharsets.UTF_16BE };
4142

@@ -88,7 +89,11 @@ void testParseTextWithFallbackJsonParser() {
8889

8990
@Test
9091
void testParseByCustomParser() {
91-
Schema schema = new SchemaParser().parse(DummySchemaParser.SCHEMA_TEXT_ONE).mainSchema();
92+
SchemaParser.ParseResult parseResult = new SchemaParser().parse(DummySchemaParser.SCHEMA_TEXT_ONE);
93+
List<Schema> namedSchemas = parseResult.parsedNamedSchemas();
94+
assertEquals(1, namedSchemas.size());
95+
assertEquals(DummySchemaParser.FIXED_SCHEMA, namedSchemas.get(0));
96+
Schema schema = parseResult.mainSchema();
9297
assertEquals(DummySchemaParser.FIXED_SCHEMA, schema);
9398
}
9499

lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void setUp() {
8787

8888
static void assertCompilesWithJavaCompiler(File dstDir, Collection<SpecificCompiler.OutputFile> outputs)
8989
throws IOException {
90-
assertCompilesWithJavaCompiler(dstDir, outputs, false);
90+
assertCompilesWithJavaCompiler(dstDir, outputs, true);
9191
}
9292

9393
/**

lang/java/idl/src/main/java/org/apache/avro/idl/IdlReader.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ private Schema namedSchemaOrUnresolved(String fullName) {
164164
return parseContext.find(fullName, null);
165165
}
166166

167-
private void addSchema(Schema schema) {
168-
parseContext.put(schema);
169-
}
170-
171167
public IdlFile parse(Path location) throws IOException {
172168
return parse(location.toUri());
173169
}
@@ -437,7 +433,7 @@ public void exitImportStatement(ImportStatementContext importContext) {
437433
try (InputStream stream = importLocation.toURL().openStream()) {
438434
Protocol importProtocol = Protocol.parse(stream);
439435
for (Schema s : importProtocol.getTypes()) {
440-
addSchema(s);
436+
parseContext.put(s);
441437
}
442438
if (protocol != null) {
443439
protocol.getMessages().putAll(importProtocol.getMessages());
@@ -515,7 +511,7 @@ public void exitFixedDeclaration(FixedDeclarationContext ctx) {
515511
Schema schema = Schema.createFixed(name, doc, space, size);
516512
properties.copyAliases(schema::addAlias);
517513
properties.copyProperties(schema);
518-
addSchema(schema);
514+
parseContext.put(schema);
519515
}
520516

521517
@Override
@@ -539,7 +535,7 @@ public void exitEnumDeclaration(EnumDeclarationContext ctx) {
539535
enumSymbols.clear();
540536
enumDefaultSymbol = null;
541537

542-
addSchema(schema);
538+
parseContext.put(schema);
543539
}
544540

545541
@Override
@@ -590,7 +586,7 @@ public void enterRecordBody(RecordBodyContext ctx) {
590586
public void exitRecordDeclaration(RecordDeclarationContext ctx) {
591587
schema.setFields(fields);
592588
fields.clear();
593-
addSchema(schema);
589+
parseContext.put(schema);
594590
schema = null;
595591

596592
popNamespace();

lang/java/mapred/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
<forkCount>1</forkCount>
9393
<reuseForks>false</reuseForks>
9494
<parallel>none</parallel>
95+
<!-- Required for recent JDKs (fixes "UnsupportedOperationException: getSubject is supported only if a security manager is allowed") -->
96+
<argLine>-Djava.security.manager=allow</argLine>
9597
</configuration>
9698
</plugin>
9799
<plugin>

lang/java/tools/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@
158158
<forkCount>1</forkCount>
159159
<reuseForks>false</reuseForks>
160160
<parallel>none</parallel>
161+
<!-- Required for recent JDKs (fixes "UnsupportedOperationException: getSubject is supported only if a security manager is allowed") -->
162+
<argLine>-Djava.security.manager=allow</argLine>
161163
</configuration>
162164
</plugin>
163165
<!-- Allow guava because hadoop brings it as a transitive dependency. -->

lang/java/trevni/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
<forkCount>1</forkCount>
5656
<reuseForks>false</reuseForks>
5757
<parallel>none</parallel>
58+
<!-- Required for recent JDKs (fixes "UnsupportedOperationException: getSubject is supported only if a security manager is allowed") -->
59+
<argLine>-Djava.security.manager=allow</argLine>
5860
</configuration>
5961
</plugin>
6062
</plugins>

0 commit comments

Comments
 (0)