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 Dec 17, 2024
1 parent 653b485 commit 55fca76
Show file tree
Hide file tree
Showing 42 changed files with 251 additions and 147 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 @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.concurrent.atomic.AtomicInteger;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -50,14 +51,14 @@ void format(Writer writer) throws IOException {
writer.write(transformToXmlString(ruleConfig));
}

private AgeOffRuleLoader.RuleConfig createRuleConfig(AgeOffRuleConfiguration configuration) throws IOException {
AgeOffRuleLoader.RuleConfig ruleConfig = new AgeOffRuleLoader.RuleConfig(this.configuration.getFilterClass().getName(), index++);
private static AgeOffRuleLoader.RuleConfig createRuleConfig(AgeOffRuleConfiguration configuration) throws IOException {
AgeOffRuleLoader.RuleConfig ruleConfig = new AgeOffRuleLoader.RuleConfig(configuration.getFilterClass().getName(), index++);
ruleConfig.label(configuration.getRuleLabel());
ruleConfig.setIsMerge(this.configuration.shouldMerge());
ruleConfig.ttlValue(this.configuration.getTtlDuration());
ruleConfig.ttlUnits(this.configuration.getTtlUnits());
ruleConfig.matchPattern(buildMatchPattern());
ruleConfig.customElements(this.configuration.getCustomElements());
ruleConfig.setIsMerge(configuration.shouldMerge());
ruleConfig.ttlValue(configuration.getTtlDuration());
ruleConfig.ttlUnits(configuration.getTtlUnits());
ruleConfig.matchPattern(buildMatchPattern(configuration, configuration.getIndentation()));
ruleConfig.customElements(configuration.getCustomElements());
return ruleConfig;
}

Expand Down Expand Up @@ -93,7 +94,7 @@ private String calculateIndentAmount() {
return Integer.toString(length);
}

private String buildMatchPattern() throws IOException {
private static String buildMatchPattern(AgeOffRuleConfiguration configuration, String indent) throws IOException {
if (configuration.getPatternConfiguration() == null) {
return "";
}
Expand All @@ -104,14 +105,14 @@ private String buildMatchPattern() throws IOException {
AgeOffCsvToMatchPatternFormatter patternFormatter = new AgeOffCsvToMatchPatternFormatter(configuration.getPatternConfiguration());

// add two indentations: one for items under the rule element and another for items under the matchPattern element
String extraIndentation = this.indent + this.indent;
String extraIndentation = indent + indent;
patternFormatter.write(new IndentingDelegatingWriter(extraIndentation, writer));

String result = writer.toString();

// final indentation to precede the closing of matchPattern
if (result.endsWith("\n")) {
return result + this.indent;
return result + indent;
}
return result;
}
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
32 changes: 16 additions & 16 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 UNKNOWN_EDGE_KEY_FORMAT_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(UNKNOWN_EDGE_KEY_FORMAT_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(UNKNOWN_EDGE_KEY_FORMAT_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(UNKNOWN_EDGE_KEY_FORMAT_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(UNKNOWN_EDGE_KEY_FORMAT_MSG + this);
}
}

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.

14 changes: 7 additions & 7 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public class BulkInputFormat extends InputFormat<Key,Value> {
protected static final String RANGESPLITSTRATEGY = PREFIX + ".split.strategy.class";
protected static final String MOCK = ".useInMemoryInstance";

protected static final String UTF8 = "UTF-8";

protected static final String RANGES = PREFIX + ".ranges";
protected static final String AUTO_ADJUST_RANGES = PREFIX + ".ranges.autoAdjust";

Expand Down Expand Up @@ -1296,8 +1298,8 @@ public AccumuloIteratorOption(String iteratorOption) {
StringTokenizer tokenizer = new StringTokenizer(iteratorOption, FIELD_SEP);
this.iteratorName = tokenizer.nextToken();
try {
this.key = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
this.value = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
this.key = URLDecoder.decode(tokenizer.nextToken(), UTF8);
this.value = URLDecoder.decode(tokenizer.nextToken(), UTF8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
Expand All @@ -1318,7 +1320,7 @@ public String getValue() {
@Override
public String toString() {
try {
return iteratorName + FIELD_SEP + URLEncoder.encode(key, "UTF-8") + FIELD_SEP + URLEncoder.encode(value, "UTF-8");
return iteratorName + FIELD_SEP + URLEncoder.encode(key, "UTF8") + FIELD_SEP + URLEncoder.encode(value, "UTF8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
Expand Down
Loading

0 comments on commit 55fca76

Please sign in to comment.