Skip to content

Commit

Permalink
Transporter: avoid using private constructor of AssertionError
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Jan 8, 2024
1 parent 0676f98 commit b757c7a
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void generateEntityTransporter(List<EntityModel> entityModels,
for (EntityModel entityModel : entityModels) {
typeSwitch.caseOf(entityModel.name, t -> t.returnValue(t.loadClass(entityModel.name)));
}
typeSwitch.defaultCase(t -> t.throwException(AssertionError.class, "Unknown entity model"));
typeSwitch.defaultCase(t -> throwAssertionError(t, "Unknown entity model"));
}
// FIXME: signature?
try (MethodCreator m = c.getMethodCreator("instantiate", PanacheEntityBase.class, String.class)
Expand All @@ -199,7 +199,7 @@ private void generateEntityTransporter(List<EntityModel> entityModels,
typeSwitch.caseOf(entityModel.name,
t -> t.returnValue(t.newInstance(MethodDescriptor.ofConstructor(entityModel.name))));
}
typeSwitch.defaultCase(t -> t.throwException(AssertionError.class, "Unknown entity model"));
typeSwitch.defaultCase(t -> throwAssertionError(t, "Unknown entity model"));
}
}
}
Expand Down Expand Up @@ -555,7 +555,7 @@ private void generateDeserializer(ClassInfo entityClassInfo, EntityModel entityM
t.assign(var, readValue);
});
fieldNameSwitch.defaultCase(t -> {
t.throwException(AssertionError.class, "Don't know what to do with field");
throwAssertionError(t, "Don't know what to do with field");
});
}
}
Expand Down Expand Up @@ -596,12 +596,17 @@ private void generateDeserializer(ClassInfo entityClassInfo, EntityModel entityM

private void assertt(BranchResult assertion) {
try (BytecodeCreator assertionFailedBranch = assertion.trueBranch()) {
assertionFailedBranch.throwException(
assertionFailedBranch.newInstance(MethodDescriptor.ofConstructor(AssertionError.class, Object.class),
assertionFailedBranch.load("Assertion failed")));
throwAssertionError(assertionFailedBranch, "Assertion failed");
assertionFailedBranch.returnVoid();
}
assertion.falseBranch().close();

}

private void throwAssertionError(BytecodeCreator creator, String message) {
// can't use creator.throwException(AssertionError, message) because that constructor is private
creator.throwException(
creator.newInstance(MethodDescriptor.ofConstructor(AssertionError.class, Object.class),
creator.load(message)));
}
}

0 comments on commit b757c7a

Please sign in to comment.