Skip to content

Commit

Permalink
preserve root cause of SpecificCompiler instantiation failure, also a…
Browse files Browse the repository at this point in the history
…vro 1.10.2 (#201)

resolves #197
  • Loading branch information
radai-rosenblatt authored Sep 25, 2021
1 parent e2de48d commit c1ab693
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 20 deletions.
4 changes: 2 additions & 2 deletions avro-fastserde/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def AVRO_1_6 = "org.apache.avro:avro:1.6.3"
def AVRO_1_7 = "org.apache.avro:avro:1.7.7"
def AVRO_1_8 = "org.apache.avro:avro:1.8.2"
def AVRO_1_9 = "org.apache.avro:avro:1.9.2"
def AVRO_1_10 = "org.apache.avro:avro:1.10.0"
def AVRO_1_10 = "org.apache.avro:avro:1.10.2"
def USE_AVRO_1_4 = project.hasProperty("USE_AVRO_1_4") ? true : false
def USE_AVRO_1_5 = project.hasProperty("USE_AVRO_1_5") ? true : false
def USE_AVRO_1_6 = project.hasProperty("USE_AVRO_1_6") ? true : false
Expand Down Expand Up @@ -132,7 +132,7 @@ dependencies {
exclude group: "org.slf4j"
}

codegenCompile ("org.apache.avro:avro-compiler:1.10.0") {
codegenCompile ("org.apache.avro:avro-compiler:1.10.2") {
exclude group: "org.slf4j"
}
codegenCompile project(":avro-fastserde")
Expand Down
4 changes: 2 additions & 2 deletions avro-fastserde/regenerate_avro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEFAULT_AVRO_TOOLS_163_JAR="avro_tools/avro_tools_163/avro-tools-1.6.3.jar"
DEFAULT_AVRO_TOOLS_177_JAR="avro_tools/avro_tools_177/avro-tools-1.7.7.jar"
DEFAULT_AVRO_TOOLS_182_JAR="avro_tools/avro_tools_182/avro-tools-1.8.2.jar"
DEFAULT_AVRO_TOOLS_192_JAR="avro_tools/avro_tools_192/avro-tools-1.9.2.jar"
DEFAULT_AVRO_TOOLS_1100_JAR="avro_tools/avro_tools_1100/avro-tools-1.10.0.jar"
DEFAULT_AVRO_TOOLS_1100_JAR="avro_tools/avro_tools_1100/avro-tools-1.10.2.jar"

if [ ! -f $DEFAULT_AVRO_TOOLS_140_JAR ]; then
mkdir -p avro_tools/avro_tools_140 && pushd . && cd avro_tools/avro_tools_140
Expand Down Expand Up @@ -44,7 +44,7 @@ if [ ! -f $DEFAULT_AVRO_TOOLS_192_JAR ]; then
fi
if [ ! -f $DEFAULT_AVRO_TOOLS_1100_JAR ]; then
mkdir -p avro_tools/avro_tools_1100 && pushd . && cd avro_tools/avro_tools_1100
curl -s -L -O -C - "https://repo1.maven.org/maven2/org/apache/avro/avro-tools/1.10.0/avro-tools-1.10.0.jar" -o avro-tools-1.10.0.jar
curl -s -L -O -C - "https://repo1.maven.org/maven2/org/apache/avro/avro-tools/1.10.2/avro-tools-1.10.2.jar" -o avro-tools-1.10.2.jar
popd
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2021 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avroutil1.compatibility;

public class ExceptionUtils {

private ExceptionUtils() {
//util class
}

public static Throwable rootCause(Throwable throwable) {
if (throwable == null) {
throw new IllegalArgumentException("argument cannot be null");
}
Throwable cause = throwable;
while (cause != null && cause.getCause() != null && cause.getCause() != cause) {
cause = cause.getCause();
}
return cause;
}
}
2 changes: 1 addition & 1 deletion helper/impls/helper-impl-110/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ plugins {

dependencies {
implementation (project(":helper:helper-common"))
compileOnly ("org.apache.avro:avro:1.10.0")
compileOnly ("org.apache.avro:avro:1.10.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaParseConfiguration;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class Avro110Adapter implements AvroAdapter {
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -111,6 +114,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}
}
Expand Down Expand Up @@ -303,7 +310,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (minSupportedVersion.earlierThan(AvroVersion.AVRO_1_6) && !StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new IllegalArgumentException("StringRepresentation " + config.getStringRepresentation() + " incompatible with minimum supported avro " + minSupportedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaNormalization;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class Avro15Adapter implements AvroAdapter {
private final static Logger LOG = LoggerFactory.getLogger(Avro15Adapter.class);

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -98,6 +101,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}
}
Expand Down Expand Up @@ -301,7 +308,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (!StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new UnsupportedOperationException("generating String fields as " + config.getStringRepresentation() + " unsupported under avro " + supportedMajorVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaNormalization;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class Avro16Adapter implements AvroAdapter {
private final static Logger LOG = LoggerFactory.getLogger(Avro16Adapter.class);

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -110,6 +113,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}
}
Expand Down Expand Up @@ -313,7 +320,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (minSupportedVersion.earlierThan(AvroVersion.AVRO_1_6) && !StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new IllegalArgumentException("StringRepresentation " + config.getStringRepresentation() + " incompatible with minimum supported avro " + minSupportedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaParseConfiguration;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class Avro17Adapter implements AvroAdapter {
//compiler-related fields and methods (if the compiler jar is on the classpath)

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -132,6 +135,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}

Expand Down Expand Up @@ -369,7 +376,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (minSupportedVersion.earlierThan(AvroVersion.AVRO_1_6) && !StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new IllegalArgumentException("StringRepresentation " + config.getStringRepresentation() + " incompatible with minimum supported avro " + minSupportedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaParseConfiguration;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class Avro18Adapter implements AvroAdapter {
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -113,6 +116,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}
}
Expand Down Expand Up @@ -309,7 +316,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (minSupportedVersion.earlierThan(AvroVersion.AVRO_1_6) && !StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new IllegalArgumentException("StringRepresentation " + config.getStringRepresentation() + " incompatible with minimum supported avro " + minSupportedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.linkedin.avroutil1.compatibility.AvroVersion;
import com.linkedin.avroutil1.compatibility.CodeGenerationConfig;
import com.linkedin.avroutil1.compatibility.CodeTransformations;
import com.linkedin.avroutil1.compatibility.ExceptionUtils;
import com.linkedin.avroutil1.compatibility.FieldBuilder;
import com.linkedin.avroutil1.compatibility.SchemaBuilder;
import com.linkedin.avroutil1.compatibility.SchemaParseConfiguration;
Expand Down Expand Up @@ -68,6 +69,8 @@ public class Avro19Adapter implements AvroAdapter {
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private boolean compilerSupported;
private Throwable compilerSupportIssue;
private String compilerSupportMessage;
private Constructor<?> specificCompilerCtr;
private Method compilerEnqueueMethod;
private Method compilerCompileMethod;
Expand Down Expand Up @@ -115,6 +118,10 @@ private void tryInitializeCompilerFields() {
//if a class we directly look for above isnt found, we get ClassNotFoundException
//but if we're missing a transitive dependency we will get NoClassDefFoundError
compilerSupported = false;
compilerSupportIssue = e;
String reason = ExceptionUtils.rootCause(compilerSupportIssue).getMessage();
compilerSupportMessage = "avro SpecificCompiler class could not be found or instantiated because " + reason
+ ". please make sure you have a dependency on org.apache.avro:avro-compiler";
//ignore
}
}
Expand Down Expand Up @@ -307,7 +314,7 @@ public Collection<AvroGeneratedSourceCode> compile(
CodeGenerationConfig config
) {
if (!compilerSupported) {
throw new UnsupportedOperationException("avro compiler jar was not found on classpath. please make sure you have a dependency on org.apache.avro:avro-compiler");
throw new UnsupportedOperationException(compilerSupportMessage, compilerSupportIssue);
}
if (minSupportedVersion.earlierThan(AvroVersion.AVRO_1_6) && !StringRepresentation.CharSequence.equals(config.getStringRepresentation())) {
throw new IllegalArgumentException("StringRepresentation " + config.getStringRepresentation() + " incompatible with minimum supported avro " + minSupportedVersion);
Expand Down
6 changes: 3 additions & 3 deletions helper/tests/codegen-110/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ compileJava.dependsOn runVanillaAvroCodegen, runCompatAvroCodegen, runCompatAvro
jar.dependsOn runResourceGeneration

dependencies {
codegen "org.apache.avro:avro-tools:1.10.0"
codegen "org.apache.avro:avro-compiler:1.10.0"
codegen "org.apache.avro:avro-tools:1.10.2"
codegen "org.apache.avro:avro-compiler:1.10.2"
codegen files('../codegenClasspath')
codegen project(":helper:tests:helper-tests-common")
codegen project(":helper:helper")

//required because generated code depends on the helper
implementation project(":helper:helper")
implementation "org.apache.avro:avro:1.10.0"
implementation "org.apache.avro:avro:1.10.2"

//this block required for resource generation code
implementation project(":helper:tests:helper-tests-common")
Expand Down
4 changes: 2 additions & 2 deletions helper/tests/helper-tests-110/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dependencies {
exclude group: "org.apache.avro"
}

testImplementation "org.apache.avro:avro:1.10.0"
testImplementation "org.apache.avro:avro-compiler:1.10.0"
testImplementation "org.apache.avro:avro:1.10.2"
testImplementation "org.apache.avro:avro-compiler:1.10.2"
testImplementation "com.google.guava:guava:28.2-jre"
testImplementation "org.mockito:mockito-core:3.2.4"
}
6 changes: 3 additions & 3 deletions helper/tests/helper-tests-allavro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ dependencies {
exclude group: "org.slf4j"
}

avro110 ("org.apache.avro:avro:1.10.0") {
avro110 ("org.apache.avro:avro:1.10.2") {
exclude group: "org.slf4j"
}
avro110 ("org.apache.avro:avro-compiler:1.10.0") {
avro110 ("org.apache.avro:avro-compiler:1.10.2") {
exclude group: "org.slf4j"
}
avro110NoCompiler ("org.apache.avro:avro:1.10.0") {
avro110NoCompiler ("org.apache.avro:avro:1.10.2") {
exclude group: "org.slf4j"
}
}
Expand Down
2 changes: 1 addition & 1 deletion parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies {
implementation "org.glassfish:jakarta.json:2.0.1"

testImplementation project(":test-common")
testImplementation "org.apache.avro:avro:1.10.0"
testImplementation "org.apache.avro:avro:1.10.2"
}

0 comments on commit c1ab693

Please sign in to comment.