Skip to content

Commit

Permalink
Sonarlint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashah-splunk committed Oct 27, 2023
1 parent 76ceb19 commit 5ccfc9b
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 46 deletions.
1 change: 0 additions & 1 deletion splunk/src/main/java/com/splunk/AtomFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.*;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamConstants;

/**
* The {@code AtomFeed} class represents an Atom feed.
Expand Down
4 changes: 2 additions & 2 deletions splunk/src/main/java/com/splunk/CollectionArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CollectionArgs extends Args {
/**
* Indicates whether to sort entries in ascending or descending order.
*/
public static enum SortDirection {
public enum SortDirection {
/** Sort entries in ascending order. */
ASC("asc"),
/** Sort entries in descending order. */
Expand All @@ -49,7 +49,7 @@ public String toString() {
/**
* Indicates the sorting mode for entries.
*/
public static enum SortMode {
public enum SortMode {
/**
* If all values of the field are numbers, collate numerically.
* Otherwise, collate alphabetically.
Expand Down
5 changes: 3 additions & 2 deletions splunk/src/main/java/com/splunk/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -190,7 +189,9 @@ else if (type == Integer.class) {
java.lang.reflect.Field field = this.getClass().getField(name);
field.set(this, value);
}
catch (NoSuchFieldException e) { continue; }
catch (NoSuchFieldException e) {
continue;
}
catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
}
Expand Down
4 changes: 2 additions & 2 deletions splunk/src/main/java/com/splunk/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* data model objects, which specify structured views on Splunk data.
*/
public class DataModel extends Entity {
private final static JsonParser jsonParser = new JsonParser();
private final static Gson gson = new Gson();
private static final JsonParser jsonParser = new JsonParser();
private static final Gson gson = new Gson();

private static final String ACCELERATION_LABEL = "acceleration";
private static final String MODEL_NAME_LABEL = "modelName";
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/main/java/com/splunk/DataModelField.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private DataModelField() {}
/**
* @return The name of this field.
*/
public String getName() { return this.name; };
public String getName() { return this.name; }

/**
* Return the name of the data model object on which this field is defined. That need not
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/main/java/com/splunk/FieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String toString() {
}
};

private final static Map<String, FieldType> typeLookup = new HashMap<>() {{
private static final Map<String, FieldType> typeLookup = new HashMap<>() {{
put("string", STRING);
put("number", NUMBER);
put("boolean", BOOLEAN);
Expand Down
3 changes: 1 addition & 2 deletions splunk/src/main/java/com/splunk/ResultsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;

/**
Expand Down Expand Up @@ -60,7 +59,7 @@ public void close() throws IOException {
* {@link Event} class to interpret multi-item values.
* @throws IOException On IO exception.
*/
final public Event getNextEvent() throws IOException {
public final Event getNextEvent() throws IOException {
return getNextElement();
}

Expand Down
2 changes: 1 addition & 1 deletion splunk/src/main/java/com/splunk/modularinput/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class Argument {
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

public enum DataType { BOOLEAN, NUMBER, STRING };
public enum DataType { BOOLEAN, NUMBER, STRING }

// Name used to identify this argument in Splunk.
protected String name;
Expand Down
6 changes: 4 additions & 2 deletions splunk/src/main/java/com/splunk/modularinput/EventWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.*;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.util.logging.Level;

/**
* The {@code EventWriter} class encapsulates writing events and error messages to Splunk from a modular input.
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/main/java/com/splunk/modularinput/Scheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class Scheme {
private static DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

public enum StreamingMode { SIMPLE, XML };
public enum StreamingMode { SIMPLE, XML }

// Name of this module input kind. <tt>title</tt> will be used as the URL scheme when
// specifying particular modular inputs. For example, if <tt>title</tt> is <tt>"abc"</tt>,
Expand Down
4 changes: 2 additions & 2 deletions splunk/src/test/java/com/splunk/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testForSetupPresent() throws Exception {
new ByteArrayInputStream(setupXml.getBytes("UTF-8")));
parsedSetupXml.getDocumentElement().normalize();

Assert.assertEquals(parsedSetupXml.getDocumentElement().getNodeName(), "SetupInfo");
Assert.assertEquals("SetupInfo", parsedSetupXml.getDocumentElement().getNodeName());

NodeList blocks = parsedSetupXml.getDocumentElement().getElementsByTagName("block");
Assert.assertEquals(1, blocks.getLength());
Expand All @@ -113,7 +113,7 @@ public void testArchive() {
Assert.assertTrue(filePath.endsWith(applicationName + ".spl"));
}
Assert.assertFalse(archive.getRefresh());
Assert.assertTrue(archive.getUrl() != null);
Assert.assertNotNull(archive.getUrl());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/test/java/com/splunk/EntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public void testResourceCollection() {
Assert.assertTrue(indexes.equals(indexes.items));
Assert.assertTrue(indexes.hashCode() != 0);
Assert.assertTrue(indexes.keySet().contains("main"));
Assert.assertTrue(indexes.valueSize("main") == 1);
Assert.assertEquals(1, indexes.valueSize("main"));
}
}
6 changes: 3 additions & 3 deletions splunk/src/test/java/com/splunk/HttpServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testRequestMessage() {
Assert.assertTrue(request.checkMethod(request.getMethod()));
request.setMethod("POST");
Assert.assertTrue(request.checkMethod(request.getMethod()));
Assert.assertEquals(request.getMethod(), "POST");
Assert.assertEquals("POST", request.getMethod());

ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
Expand All @@ -102,8 +102,8 @@ public void testRequestMessage() {
@Test
public void testResponseMessage() {
ResponseMessage response = new ResponseMessage(200);
Assert.assertEquals(response.getStatus(), 200);
Assert.assertTrue(response.getHeader() != null);
Assert.assertEquals(200, response.getStatus());
Assert.assertNotNull(response.getHeader());
}

@Test(expected = IllegalArgumentException.class)
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/test/java/com/splunk/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public void testUploadArgsFailure() throws Exception{
Assert.fail("Uploading to an index with an index argument? No need for redundancy!");
}
catch(Exception e){
Assert.assertEquals(e.getMessage(), "The 'index' parameter cannot be passed to an index's oneshot upload.");
Assert.assertEquals("The 'index' parameter cannot be passed to an index's oneshot upload.", e.getMessage());
}

}
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/test/java/com/splunk/InputCrudTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public void testWindowsPerfmonInputCrud() {

Assert.assertEquals(1, windowsPerfmonInput.getCounters().length);
Assert.assertTrue(contains(windowsPerfmonInput.getCounters(), "% Privileged Time"));
Assert.assertEquals(windowsPerfmonInput.getIndex(), "main");
Assert.assertEquals("main", windowsPerfmonInput.getIndex());
Assert.assertTrue(contains(windowsPerfmonInput.getInstances(), "wininit"));
Assert.assertEquals(1200, windowsPerfmonInput.getInterval());
Assert.assertEquals("Process", windowsPerfmonInput.getObject());
Expand Down
8 changes: 2 additions & 6 deletions splunk/src/test/java/com/splunk/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,8 @@ public void testNamespaceConflicts() {
Assert.assertEquals(query1, service.getSavedSearches(namespace1).get(savedSearchName).getSearch());
Assert.assertEquals(query2, service.getSavedSearches(namespace2).get(savedSearchName).getSearch());

try {
service.getSavedSearches(wildcardNamespace).get(savedSearchName).getSearch();
Assert.fail("Expected SplunkException about multiple keys.");
} catch (SplunkException e) {

}
service.getSavedSearches(wildcardNamespace).get(savedSearchName).getSearch();
Assert.fail("Expected SplunkException about multiple keys.");
} finally {
if (service.getSavedSearches(namespace1).containsKey(savedSearchName)) {
service.getSavedSearches(namespace1).remove(savedSearchName);
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/test/java/com/splunk/OutputDefaultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testOutputDefault() throws Exception {
// Probe
{
outputDefault.setMaxQueueSize("1MB");
Assert.assertEquals(outputDefault.getMaxQueueSize(), "1MB");
Assert.assertEquals("1MB", outputDefault.getMaxQueueSize());
outputDefault.setMaxQueueSize(maxQueueSize);
Assert.assertEquals(outputDefault.getMaxQueueSize(), maxQueueSize);

Expand Down
4 changes: 2 additions & 2 deletions splunk/src/test/java/com/splunk/PasswordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testPasswordsWithWildCards(){
args.put("password", "changed!");
Service service = Service.connect(args);
PasswordCollection passwords = service.getPasswords();
Assert.assertEquals(passwords.size(),0);
Assert.assertEquals(0, passwords.size());

String name = "no-owner";
String value = "sdk-test-password";
Expand Down Expand Up @@ -171,6 +171,6 @@ public void testPasswordsWithWildCards(){
Assert.assertEquals("app context must be specified when removing a password.", e.getMessage());
}
passwords = service.getPasswords();
Assert.assertEquals(passwords.size(),0);
Assert.assertEquals(0, passwords.size());
}
}
8 changes: 4 additions & 4 deletions splunk/src/test/java/com/splunk/ResultsReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void testPreviewSingleReaderXml(boolean useIter) throws Exception {
String[] fieldNameArray = new String[0];
fieldNameArray = reader.getFields().toArray(fieldNameArray);
Assert.assertEquals(101, fieldNameArray.length);
Assert.assertEquals(fieldNameArray[99], "useragent");
Assert.assertEquals("useragent", fieldNameArray[99]);

int index = 0;
Event lastEvent = null;
Expand Down Expand Up @@ -456,13 +456,13 @@ private void testExportMultiReader(

switch (indexResultSet) {
case 0:
Assert.assertEquals(indexEvent, 1);
Assert.assertEquals(1, indexEvent);
break;
case 1:
Assert.assertEquals(indexEvent, 3);
Assert.assertEquals(3, indexEvent);
break;
default:
Assert.assertEquals(indexEvent, 5);
Assert.assertEquals(5, indexEvent);
break;
}
indexResultSet++;
Expand Down
6 changes: 3 additions & 3 deletions splunk/src/test/java/com/splunk/SavedSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void testUpdate() {

boolean isPre620 = service.versionIsEarlierThan("6.2.0");
try {
Assert.assertEquals(savedSearch.isEmbedEnabled(), false);
Assert.assertEquals(false, savedSearch.isEmbedEnabled());
Assert.assertNull(savedSearch.getEmbedToken());
if (isPre620)
Assert.fail("Expected UnsupportedOperationException");
Expand Down Expand Up @@ -373,8 +373,8 @@ public void testACLUpdates(){
args.add("perms.read","admin, nobody");
savedSearch.aclUpdate(args);
aclInfo = savedSearch.getMetadata().getEaiAcl();
Assert.assertEquals(aclInfo.getString("sharing"), "app");
Assert.assertEquals(aclInfo.getString("owner"), "nobody");
Assert.assertEquals("app", aclInfo.getString("sharing"));
Assert.assertEquals("nobody", aclInfo.getString("owner"));
Assert.assertNotNull(aclInfo.get("perms"));
}

Expand Down
10 changes: 5 additions & 5 deletions splunk/src/test/java/com/splunk/SearchJobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void testEventArgs(Job job) throws IOException, InterruptedException {
while(true) {
HashMap<String, String> found = reader.getNextEvent();
if (found != null) {
Assert.assertEquals(found.get("_raw").split("\n").length, 1);
Assert.assertEquals(1, found.get("_raw").split("\n").length);
Assert.assertFalse(found.containsKey("date_month"));
Assert.assertEquals(Integer.parseInt(found.get("_serial")), count + 2);
count++;
Expand All @@ -367,7 +367,7 @@ public void testResultArgs(Job job) throws IOException, InterruptedException {
while(true) {
HashMap<String, String> found = reader.getNextEvent();
if (found != null) {
Assert.assertEquals(found.get("_raw").split("\n").length, 1);
Assert.assertEquals(1, found.get("_raw").split("\n").length);
Assert.assertFalse(found.containsKey("date_month"));
Assert.assertEquals(Integer.parseInt(found.get("_serial")), count + 2);
count++;
Expand All @@ -390,7 +390,7 @@ public void testResultArgs(Job job) throws IOException, InterruptedException {
while(true) {
HashMap<String, String> found = reader2.getNextEvent();
if (found != null) {
Assert.assertEquals(found.get("count"), "10");
Assert.assertEquals("10", found.get("count"));
count2++;
}
else {
Expand All @@ -415,7 +415,7 @@ public void testPreviewArgs(Job job) throws IOException, InterruptedException {
while (true) {
HashMap<String, String> found = reader.getNextEvent();
if (found != null) {
Assert.assertEquals(found.get("_raw").split("\n").length, 1);
Assert.assertEquals(1, found.get("_raw").split("\n").length);
Assert.assertFalse(found.containsKey("date_month"));
Assert.assertEquals(Integer.parseInt(found.get("_serial")), count + 2);
count++;
Expand All @@ -438,7 +438,7 @@ public void testPreviewArgs(Job job) throws IOException, InterruptedException {
while(true) {
HashMap<String, String> found = reader2.getNextEvent();
if (found != null) {
Assert.assertEquals(found.get("count"), "10");
Assert.assertEquals("10", found.get("count"));
count2++;
}
else {
Expand Down
4 changes: 2 additions & 2 deletions splunk/src/test/java/com/splunk/ServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void testServiceWithCustomHeaders() {
}});
Service service = new Service(args);
Map<String, String> customHeaders = service.getCustomHeaders();
Assert.assertEquals(customHeaders.get("some header key"), "some value");
Assert.assertEquals("some value", customHeaders.get("some header key"));
}

@Test
Expand Down Expand Up @@ -522,7 +522,7 @@ public void testNewServiceArgs() {
args.setToken("Splunk MY_SESSION_KEY");

Assert.assertEquals("Arg setters didn't replicate value to deprecated fields.",
args.app, "myapp");
"myapp", args.app);

Service service = new Service(args);
Assert.assertEquals(args.app, service.getApp());
Expand Down

0 comments on commit 5ccfc9b

Please sign in to comment.