Skip to content

Commit

Permalink
[Validation] determine whether or not to allow empty tags based on a …
Browse files Browse the repository at this point in the history
…system property passed in to the codec generator
  • Loading branch information
writeoncereadmany committed Nov 30, 2023
1 parent d465cbb commit c78d936
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class CodecConfiguration
public static final String WRAP_EMPTY_BUFFER = "fix.codecs.wrap_empty_buffer";
public static final String PARENT_PACKAGE_PROPERTY = "fix.codecs.parent_package";
public static final String FLYWEIGHTS_ENABLED_PROPERTY = "fix.codecs.flyweight";
public static final String ALLOW_EMPTY_TAGS_PROPERTY = "fix.codecs.allow.empty.fix.tags";
public static final String REJECT_UNKNOWN_ENUM_VALUE_PROPERTY = "reject.unknown.enum.value";
public static final String FIX_TAGS_IN_JAVADOC = "fix.codecs.tags_in_javadoc";

Expand All @@ -63,6 +64,7 @@ public final class CodecConfiguration
private String parentPackage = System.getProperty(PARENT_PACKAGE_PROPERTY, DEFAULT_PARENT_PACKAGE);
private boolean flyweightsEnabled = Boolean.getBoolean(FLYWEIGHTS_ENABLED_PROPERTY);
private boolean wrapEmptyBuffer = Boolean.getBoolean(WRAP_EMPTY_BUFFER);
private boolean allowEmptyTags = Boolean.getBoolean(ALLOW_EMPTY_TAGS_PROPERTY);
private boolean fixTagsInJavadoc = Boolean.parseBoolean(System.getProperty(
FIX_TAGS_IN_JAVADOC, DEFAULT_FIX_TAGS_IN_JAVADOC));
private SharedCodecConfiguration sharedCodecConfiguration;
Expand Down Expand Up @@ -114,6 +116,12 @@ public CodecConfiguration flyweightsEnabled(final boolean flyweightsEnabled)
return this;
}

public CodecConfiguration allowEmptyTags(final boolean allowEmptyTags)
{
this.allowEmptyTags = allowEmptyTags;
return this;
}

/**
* Suppresses checks for the presence of optional string fields (i.e. no exception is
* thrown when unset, instead the AsciiSequenceView wraps an empty buffer).
Expand Down Expand Up @@ -248,6 +256,11 @@ boolean wrapEmptyBuffer()
return wrapEmptyBuffer;
}

boolean allowEmptyTags()
{
return allowEmptyTags;
}

String codecRejectUnknownEnumValueEnabled()
{
return codecRejectUnknownEnumValueEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static void generate(final CodecConfiguration configuration) throws Excep

final String outputPath = configuration.outputPath();
final String codecRejectUnknownEnumValueEnabled = configuration.codecRejectUnknownEnumValueEnabled();
final String codecRejectEmptyTagsEnabled = configuration.codecRejectUnknownEnumValueEnabled();

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'String codecRejectEmptyTagsEnabled' is never read.

final boolean hasSharedCodecs = configuration.sharedCodecConfiguration() != null;
if (hasSharedCodecs)
Expand Down Expand Up @@ -182,7 +183,7 @@ private static void generateDictionary(
RejectUnknownEnumValue.class,
false,
configuration.wrapEmptyBuffer(),
false,
configuration.allowEmptyTags(),
codecRejectUnknownEnumValueEnabled,
configuration.fixTagsInJavadoc()).generate();

Expand All @@ -205,7 +206,7 @@ private static void generateDictionary(
RejectUnknownEnumValue.class,
true,
configuration.wrapEmptyBuffer(),
false,
configuration.allowEmptyTags(),
codecRejectUnknownEnumValueEnabled,
configuration.fixTagsInJavadoc()).generate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public abstract class Generator
public static final String BODY_LENGTH = "BodyLength";

public static final String CODEC_VALIDATION_ENABLED = "CODEC_VALIDATION_ENABLED";
public static final String CODEC_REJECT_EMPTY_TAG_ENABLED = "CODEC_REJECT_EMPTY_TAG_ENABLED";
public static final String CODEC_REJECT_UNKNOWN_FIELD_ENABLED = "CODEC_REJECT_UNKNOWN_FIELD_ENABLED";
public static final String RUNTIME_REJECT_UNKNOWN_ENUM_VALUE_PROPERTY = "CODEC_REJECT_UNKNOWN_ENUM_VALUE_ENABLED";
public static final Pattern NEWLINE = Pattern.compile("^", MULTILINE);
Expand Down

0 comments on commit c78d936

Please sign in to comment.