Skip to content

Commit

Permalink
Remove sneaky throws. (#20931)
Browse files Browse the repository at this point in the history
The Java 19 toolchain doesn't like sneaky throws. Not entirely sure why. However, I think it's better practice to not use sneaky throws as it makes it clearer what is throw and where.

Example error message when trying to compile the current codebase with Java 19:

error: Error during the transformation of 'io.airbyte.validation.json.JsonSchemaValidatorTest'; post-compiler 'lombok.bytecode.SneakyThrowsRemover' caused an exception: java.lang.IllegalArgumentException: Unsupported class file major version 63
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:199)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:180)
        at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
        at lombok.bytecode.AsmUtil.fixJSRInlining(AsmUtil.java:37)
        at lombok.bytecode.SneakyThrowsRemover.applyTransformations(SneakyThrowsRemover.java:46)
        at lombok.core.PostCompiler.applyTransformations(PostCompiler.java:44)
        at lombok.core.PostCompiler$1.close(PostCompiler.java:87)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1508)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:738)
  • Loading branch information
davinchia authored Dec 30, 2022
1 parent baf9d11 commit 18593d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.net.URI;
import java.net.URISyntaxException;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -27,7 +28,7 @@ void testVersionMetadata() {
}

@Test
void testDowngrade() {
void testDowngrade() throws URISyntaxException {
final io.airbyte.protocol.models.v0.AirbyteMessage v0Message = getV0Message();

final io.airbyte.protocol.models.AirbyteMessage downgradedMessage = v0migration.downgrade(v0Message);
Expand All @@ -36,16 +37,15 @@ void testDowngrade() {
}

@Test
void testUpgrade() {
void testUpgrade() throws URISyntaxException {
final io.airbyte.protocol.models.AirbyteMessage unversionedMessage = getUnversionedMessage();

final io.airbyte.protocol.models.v0.AirbyteMessage upgradedMessage = v0migration.upgrade(unversionedMessage);
final io.airbyte.protocol.models.v0.AirbyteMessage expectedMessage = getV0Message();
assertEquals(expectedMessage, upgradedMessage);
}

@SneakyThrows
private io.airbyte.protocol.models.v0.AirbyteMessage getV0Message() {
private io.airbyte.protocol.models.v0.AirbyteMessage getV0Message() throws URISyntaxException {
return new io.airbyte.protocol.models.v0.AirbyteMessage()
.withType(io.airbyte.protocol.models.v0.AirbyteMessage.Type.SPEC)
.withSpec(
Expand All @@ -54,8 +54,7 @@ private io.airbyte.protocol.models.v0.AirbyteMessage getV0Message() {
.withDocumentationUrl(new URI("file:///tmp/doc")));
}

@SneakyThrows
private io.airbyte.protocol.models.AirbyteMessage getUnversionedMessage() {
private io.airbyte.protocol.models.AirbyteMessage getUnversionedMessage() throws URISyntaxException {
return new io.airbyte.protocol.models.AirbyteMessage()
.withType(io.airbyte.protocol.models.AirbyteMessage.Type.SPEC)
.withSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ public VersionedAirbyteStreamFactory(final AirbyteMessageSerDeProvider serDeProv
* the stream rather than the one passed from the constructor.
*/
@Trace(operationName = WORKER_OPERATION_NAME)
@SneakyThrows
@Override
public Stream<AirbyteMessage> create(final BufferedReader bufferedReader) {
if (shouldDetectVersion) {
final Optional<Version> versionMaybe = detectVersion(bufferedReader);
final Optional<Version> versionMaybe;
try {
versionMaybe = detectVersion(bufferedReader);
} catch (final IOException e) {
throw new RuntimeException(e);
}
if (versionMaybe.isPresent()) {
logger.info("Detected Protocol Version {}", versionMaybe.get().serialize());
initializeForProtocolVersion(versionMaybe.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Set;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -106,9 +107,8 @@ void test() throws IOException {
assertNull(JsonSchemaValidator.getSchema(schemaFile, "NonExistentObject"));
}

@SneakyThrows
@Test
void testResolveReferences() throws IOException {
void testResolveReferences() throws IOException, URISyntaxException {
String referencableSchemas = """
{
"definitions": {
Expand Down

0 comments on commit 18593d9

Please sign in to comment.