Skip to content

Commit

Permalink
chore: Cleaned up what was causing sonar to complain about using gene…
Browse files Browse the repository at this point in the history
…ric exceptions.
  • Loading branch information
chrisdutz committed Jul 21, 2023
1 parent 3917dab commit 4c4155e
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference) {
if (integerTypeReference.getSizeInBits() <= 64) {
return "uint64_t";
}
throw new RuntimeException("Unsupported simple type");
throw new FreemarkerException("Unsupported simple type");
}
case INT: {
IntegerTypeReference integerTypeReference = (IntegerTypeReference) simpleTypeReference;
Expand All @@ -237,7 +237,7 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference) {
if (integerTypeReference.getSizeInBits() <= 64) {
return "int64_t";
}
throw new RuntimeException("Unsupported simple type");
throw new FreemarkerException("Unsupported simple type");
}
case FLOAT:
FloatTypeReference floatTypeReference = (FloatTypeReference) simpleTypeReference;
Expand Down Expand Up @@ -290,7 +290,7 @@ public String getDataIoTypeNameForTypeReference(TypeReference typeReference) {
if (integerTypeReference.getSizeInBits() <= 64) {
return "ulint";
}
throw new RuntimeException("Unsupported simple type");
throw new FreemarkerException("Unsupported simple type");
}
case INT: {
IntegerTypeReference integerTypeReference = (IntegerTypeReference) simpleTypeReference;
Expand All @@ -306,7 +306,7 @@ public String getDataIoTypeNameForTypeReference(TypeReference typeReference) {
if (integerTypeReference.getSizeInBits() <= 64) {
return "lint";
}
throw new RuntimeException("Unsupported simple type");
throw new FreemarkerException("Unsupported simple type");
}
case FLOAT:
FloatTypeReference floatTypeReference = (FloatTypeReference) simpleTypeReference;
Expand Down Expand Up @@ -491,7 +491,7 @@ public String getReadBufferReadMethodCall(SimpleTypeReference simpleTypeReferenc
case STRING: {
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
String length = Integer.toString(simpleTypeReference.getSizeInBits());
Expand All @@ -501,7 +501,7 @@ public String getReadBufferReadMethodCall(SimpleTypeReference simpleTypeReferenc
case VSTRING: {
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
// Here we need to use the serialized expression of the length instead.
Expand Down Expand Up @@ -562,7 +562,7 @@ public String getWriteBufferWriteMethodCall(SimpleTypeReference simpleTypeRefere
case STRING: {
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
String length = Integer.toString(simpleTypeReference.getSizeInBits());
Expand All @@ -572,7 +572,7 @@ public String getWriteBufferWriteMethodCall(SimpleTypeReference simpleTypeRefere
case VSTRING: {
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
// Here we need to use the serialized expression of the length instead.
Expand Down Expand Up @@ -895,7 +895,7 @@ private String toTypeVariableParseExpression(Field field, VariableLiteral variab
// TODO: replace with map join
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
return tracer + "\"" + encoding + "\"";
Expand Down Expand Up @@ -948,18 +948,18 @@ private String toUpperCaseVariableParseExpression(TypeDefinition baseType, Field

private String toCastVariableParseExpression(TypeDefinition baseType, Field field, VariableLiteral variableLiteral, List<Argument> parserArguments, Tracer tracer) {
tracer = tracer.dive("CAST");
List<Term> arguments = variableLiteral.getArgs().orElseThrow(() -> new RuntimeException("A Cast expression needs arguments"));
List<Term> arguments = variableLiteral.getArgs().orElseThrow(() -> new FreemarkerException("A Cast expression needs arguments"));
if (arguments.size() != 2) {
throw new RuntimeException("A CAST expression expects exactly two arguments.");
throw new FreemarkerException("A CAST expression expects exactly two arguments.");
}
VariableLiteral firstArgument = arguments.get(0).asLiteral()
.orElseThrow(() -> new RuntimeException("First argument should be a literal"))
.orElseThrow(() -> new FreemarkerException("First argument should be a literal"))
.asVariableLiteral()
.orElseThrow(() -> new RuntimeException("First argument should be a Variable literal"));
.orElseThrow(() -> new FreemarkerException("First argument should be a Variable literal"));
StringLiteral typeLiteral = arguments.get(1).asLiteral()
.orElseThrow(() -> new RuntimeException("Second argument should be a String literal"))
.orElseThrow(() -> new FreemarkerException("Second argument should be a String literal"))
.asStringLiteral()
.orElseThrow(() -> new RuntimeException("Second argument should be a String literal"));
.orElseThrow(() -> new FreemarkerException("Second argument should be a String literal"));

final TypeDefinition castType = getTypeDefinitions().get(typeLiteral.getValue());
// If we're casting to a sub-type of a discriminated value, we got to cast to the parent
Expand Down Expand Up @@ -1084,7 +1084,7 @@ private String toVariableSerializationExpression(TypeDefinition baseType, Field
}
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
return tracer + "\"" + encoding + "\"";
Expand Down Expand Up @@ -1176,7 +1176,7 @@ private String toUppercaseSerializationExpression(TypeDefinition baseType, Field
}
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
sb.append("\"").append(encoding).append("\"");
Expand Down Expand Up @@ -1253,7 +1253,7 @@ private String toStaticCallSerializationExpression(TypeDefinition baseType, Fiel
}
final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
if (!(encodingTerm instanceof StringLiteral)) {
throw new RuntimeException("Encoding must be a quoted string value");
throw new FreemarkerException("Encoding must be a quoted string value");
}
String encoding = ((StringLiteral) encodingTerm).getValue();
sb.append("\"").append(encoding).append("\"");
Expand Down
Loading

0 comments on commit 4c4155e

Please sign in to comment.