Skip to content

Commit

Permalink
fix critical sonarqube issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Gross cogross committed May 21, 2024
1 parent dbaf436 commit 482cbd0
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ default void preInitialize(Query settings, Set<Authorizations> userAuthorization
* Set a client configuration for scanner hints and consistency.
*
* @param config
* accumuloConfiguration
*/
void setClientConfig(AccumuloClientConfiguration config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public void parseHeader(String[] headerTokens) {
case DURATION_OVERRIDE_COLUMN_HEADER:
this.overrideColumnNumber = columnNumber;
break;
default:
break;
}
columnNumber++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ void format(Writer writer) throws IOException {
writer.close();
}

private static void increment() {
index++;
}

private AgeOffRuleLoader.RuleConfig createRuleConfig(AgeOffRuleConfiguration configuration) throws IOException {
AgeOffRuleLoader.RuleConfig ruleConfig = new AgeOffRuleLoader.RuleConfig(this.configuration.getFilterClass().getName(), index++);
AgeOffRuleLoader.RuleConfig ruleConfig = new AgeOffRuleLoader.RuleConfig(this.configuration.getFilterClass().getName(), index);
increment();
ruleConfig.label(configuration.getRuleLabel());
ruleConfig.setIsMerge(this.configuration.shouldMerge());
ruleConfig.ttlValue(this.configuration.getTtlDuration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void write(String line) throws IOException {
this.shouldIndentNextWrite = false;
}

String indentedLine = line.replaceAll("\n", "\n" + indentation);
String indentedLine = line.replace("\n", "\n" + indentation);

// withhold indentation until later
if (indentedLine.endsWith("\n" + indentation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import datawave.iterators.filter.ageoff.AgeOffPeriod;

public abstract class TokenSpecParser<B extends TokenSpecParser> {

private static final String UNEXPECTED_EOS_ERROR_MSG = "Unexpected end of string literal parsing escape code";

/**
* Add a new token with its TTL to the structure.
*
Expand Down Expand Up @@ -221,7 +224,7 @@ protected String parseStrliteral() {
} else {
charPos++;
if (charPos >= literalContent.length()) {
throw error("Unexpected end of string literal parsing escape code", token.offset + charPos - 1);
throw error(UNEXPECTED_EOS_ERROR_MSG, token.offset + charPos - 1);
}
c = literalContent.charAt(charPos);
switch (c) {
Expand Down Expand Up @@ -250,7 +253,7 @@ protected String parseStrliteral() {
String ordTxt = literalContent.substring(charPos + 1, charPos + 5);
if (ordTxt.length() != 4) {
if (charPos >= literalContent.length()) {
throw error("Unexpected end of string literal parsing escape code", token.offset + charPos - 1);
throw error(UNEXPECTED_EOS_ERROR_MSG, token.offset + charPos - 1);
}
}
try {
Expand All @@ -265,7 +268,7 @@ protected String parseStrliteral() {
String ordTxt = literalContent.substring(charPos + 1, charPos + 3);
if (ordTxt.length() != 2) {
if (charPos >= literalContent.length()) {
throw error("Unexpected end of string literal parsing escape code", token.offset + charPos - 1);
throw error(UNEXPECTED_EOS_ERROR_MSG, token.offset + charPos - 1);
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected static HashUID newId(final HashUID template, final String... extras) {
if (null != template) {
// Get the existing and new extras, if any
final String extra1 = template.getExtra();
final String extra2 = HashUID.mergeExtras(extras);
final String extra2 = UID.mergeExtras(extras);

// Create a new UID based on existing and new extras
if ((null != extra1) && (null != extra2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected static SnowflakeUID newId(final SnowflakeUID template, final String...
if (null != template) {
// Get the existing and new extras, if any
final String extra1 = template.getExtra();
final String extra2 = SnowflakeUID.mergeExtras(extras);
final String extra2 = UID.mergeExtras(extras);

// Create a new UID based on existing and new extras
if ((null != extra1) && (null != extra2)) {
Expand Down
34 changes: 17 additions & 17 deletions warehouse/core/src/main/java/datawave/edge/protobuf/EdgeData.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions warehouse/core/src/main/java/datawave/edge/util/EdgeKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class EdgeKey {

private static final Logger log = Logger.getLogger(EdgeKey.class);

private static final String CANT_ENCODE_UNKNOWN_ERROR_MSG = "Can't encode unknown edge key format.";

// use the builder, not this nightmare constructor
private EdgeKey(EDGE_FORMAT format, STATS_TYPE statsType, String sourceData, String sinkData, String family, String sourceRelationship,
String sinkRelationship, String sourceAttribute1, String sinkAttribute1, String yyyymmdd, String attribute3, String attribute2, Text colvis,
Expand Down Expand Up @@ -925,7 +927,7 @@ public Key encode() {
return encode(EDGE_VERSION.DATE_PROTOBUF);
} else {
// EDGE_FORMAT.UNKNOWN
throw new IllegalStateException("Can't encode unknown edge key format." + this);
throw new IllegalStateException(CANT_ENCODE_UNKNOWN_ERROR_MSG + this);
}
}

Expand All @@ -938,7 +940,7 @@ public Key encodeLegacyProtobufKey() {
return encode(EDGE_VERSION.PROTOBUF);
} else {
// EDGE_FORMAT.UNKNOWN
throw new IllegalStateException("Can't encode unknown edge key format." + this);
throw new IllegalStateException(CANT_ENCODE_UNKNOWN_ERROR_MSG + this);
}
}

Expand All @@ -949,7 +951,7 @@ public Key encodeLegacyAttribute2Key() {
return encode(EDGE_VERSION.BASE_ATTRIBUTE2);
} else {
// EDGE_FORMAT.UNKNOWN
throw new IllegalStateException("Can't encode unknown edge key format." + this);
throw new IllegalStateException(CANT_ENCODE_UNKNOWN_ERROR_MSG + this);
}
}

Expand All @@ -960,7 +962,7 @@ public Key encodeLegacyKey() {
return encode(EDGE_VERSION.BASE);
} else {
// EDGE_FORMAT.UNKNOWN
throw new IllegalStateException("Can't encode unknown edge key format." + this);
throw new IllegalStateException(CANT_ENCODE_UNKNOWN_ERROR_MSG + this);
}
}

Expand Down
10 changes: 5 additions & 5 deletions warehouse/core/src/main/java/datawave/edge/util/EdgeKeyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Utility class for generating regular expressions to scan various formats of the edge table.
*/
public class EdgeKeyUtil {
protected static final String edgeTypePrefix = "(?:^|STATS/[^/]+/)";
protected static final String EDGE_TYPE_PREFIX = "(?:^|STATS/[^/]+/)";
public static final String MAX_UNICODE_STRING = new String(Character.toChars(Character.MAX_CODE_POINT));

public static Set<String> normalizeSource(String source, List<? extends Type<?>> dataTypes, boolean protobuffEdgeFormat) {
Expand Down Expand Up @@ -183,7 +183,7 @@ public static Map<FieldKey,String> dissasembleKey(Key key, boolean protobuffEdge
public static String getEdgeColumnFamilyRegex(String edgeType, String edgeRelationship, String edgeAttribute1) {
StringBuilder cfsb = new StringBuilder();
if (edgeType != null) {
cfsb.append(edgeTypePrefix).append(edgeType).append("/");
cfsb.append(EDGE_TYPE_PREFIX).append(edgeType).append("/");
if (edgeRelationship != null && edgeAttribute1 == null) {
cfsb.append(edgeRelationship);
} else if (edgeRelationship != null && edgeAttribute1 != null) {
Expand All @@ -194,11 +194,11 @@ public static String getEdgeColumnFamilyRegex(String edgeType, String edgeRelati
cfsb.append(".*");
}
} else if (edgeRelationship != null && edgeAttribute1 == null) {
cfsb.append(edgeTypePrefix + "[^/]+/").append(edgeRelationship).append(".*");
cfsb.append(EDGE_TYPE_PREFIX + "[^/]+/").append(edgeRelationship).append(".*");
} else if (edgeAttribute1 != null && edgeRelationship == null) {
cfsb.append(edgeTypePrefix + "[^/]+/[^/]+/").append(edgeAttribute1).append(".*");
cfsb.append(EDGE_TYPE_PREFIX + "[^/]+/[^/]+/").append(edgeAttribute1).append(".*");
} else if (edgeAttribute1 != null && edgeRelationship != null) {
cfsb.append(edgeTypePrefix + "[^/]+/").append(edgeRelationship).append("/").append(edgeAttribute1).append(".*");
cfsb.append(EDGE_TYPE_PREFIX + "[^/]+/").append(edgeRelationship).append("/").append(edgeAttribute1).append(".*");
}

return cfsb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void initialize(InputSplit split, TaskAttemptContext context) throws IOEx
end = fileSplit.getLength() - start;
pos = start;

FileOperations ops = RFileOperations.getInstance();
FileOperations ops = FileOperations.getInstance();
String file = fileSplit.getPath().toString();
FileSystem fs = fileSplit.getPath().getFileSystem(context.getConfiguration());
CryptoService cs = CryptoFactoryLoader.getServiceForClient(CryptoEnvironment.Scope.TABLE,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions warehouse/core/src/main/java/datawave/ingest/protobuf/Uid.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MarkingFunctionsFactory {

@Inject
@SpringBean(refreshable = true)
private MarkingFunctions applicationMarkingFunctions;
private static MarkingFunctions applicationMarkingFunctions;

public static final Logger log = LoggerFactory.getLogger(MarkingFunctionsFactory.class);

Expand Down Expand Up @@ -59,7 +59,7 @@ public void init(@SuppressWarnings("UnusedParameters") @Observes @Initialized(Ap
}

@PostConstruct
public void postContruct() {
public static void postContruct() {
markingFunctions = applicationMarkingFunctions;
}
}
Loading

0 comments on commit 482cbd0

Please sign in to comment.