Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize codebase and increase visibility of problematic code within a developers' IDEs by reducing warnings and code inspection violations. (Up to date with master and all tests passing as-of 2/15/22) #208

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
211c0f2
Use diamond operator
Oct 25, 2021
88fcda0
Replace anonymous types with lambdas
Oct 25, 2021
ba793b0
Replace javadoc comments with block comments
Oct 25, 2021
0c0d4c9
Revert "Replace javadoc comments with block comments"
Oct 25, 2021
c3ffbd1
Replace javadoc comments with block comments
Oct 25, 2021
0b612c1
Comment is not javadoc, remove javadoc notation
Oct 25, 2021
d018701
Remove unused imports
Oct 25, 2021
676eac8
Remove unnecessary toString calls in String.format and System.out/err…
Oct 25, 2021
43f16ef
Remove unneccessary semicolon
Oct 25, 2021
75c9016
Remove un-necessary thrown clause (overridden method does not throw d…
Oct 25, 2021
017af65
Remove redundant initializers
Oct 25, 2021
e1f368d
Remove redundant annotation parameters
Oct 25, 2021
f5e29b6
Remove redundant interface method modifiers
Oct 25, 2021
da75176
Collapse identical exception handlers into single catch statement
Oct 25, 2021
10c38ba
When you synchronize on a field, it should be final
Oct 25, 2021
201591a
Remove unnecessary toString calls in String.format and System.out/err…
Oct 25, 2021
2afc16c
Duplicate key/value is added to map
Oct 25, 2021
1b555a0
Collapse exceptions in throws clause
Oct 25, 2021
c351e54
Add generics to un-parameterized Map
Oct 25, 2021
aa17af3
Use containsKey() over keySet().contains()
Oct 25, 2021
d0572fc
Remove un-necessary thrown clause (overridden method does not throw d…
Oct 25, 2021
355c47d
object equality should not be used to compare strings
Oct 25, 2021
b417687
Use primitive boolean over Boolean object when applicable
Oct 25, 2021
30d8c3f
Remove redundant casts
Oct 25, 2021
d79d267
No need to mark private method final
Oct 25, 2021
5bfdd23
Remove unneccessary semicolon
Oct 25, 2021
6cc9804
Explicit null checking
Oct 25, 2021
fc73d32
Use assertEquals or fail over always using assertTrue
Oct 25, 2021
d561060
Avoid obvious implicit casts
Oct 25, 2021
448005d
Mark fields static/final in tests
Oct 25, 2021
51acf67
logEx can never be null
Oct 26, 2021
f6646b6
Merge branch 'main' into feature/use-jdk8-source-features
Feb 15, 2022
423d85e
Remove unread collection
Feb 15, 2022
e8530bc
Fix typo
Feb 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SuppressWarnings("serial")
public final class HttpEventCollectorLog4jAppender extends AbstractAppender
{
private HttpEventCollectorSender sender = null;
private HttpEventCollectorSender sender;
private final boolean includeLoggerName;
private final boolean includeThreadName;
private final boolean includeMDC;
Expand Down Expand Up @@ -154,10 +154,10 @@ public static HttpEventCollectorLog4jAppender createAppender(
@PluginAttribute(value = "includeException", defaultBoolean = true) final boolean includeException,
@PluginAttribute(value = "includeMarker", defaultBoolean = true) final boolean includeMarker,
@PluginAttribute(value = "connect_timeout", defaultLong = HttpEventCollectorSender.TimeoutSettings.DEFAULT_CONNECT_TIMEOUT) final long connectTimeout,
@PluginAttribute(value = "call_timeout", defaultLong = HttpEventCollectorSender.TimeoutSettings.DEFAULT_CALL_TIMEOUT) final long callTimeout,
@PluginAttribute(value = "read_timeout", defaultLong = HttpEventCollectorSender.TimeoutSettings.DEFAULT_READ_TIMEOUT) final long readTimeout,
@PluginAttribute(value = "write_timeout", defaultLong = HttpEventCollectorSender.TimeoutSettings.DEFAULT_WRITE_TIMEOUT) final long writeTimeout,
@PluginAttribute(value = "termination_timeout", defaultLong = HttpEventCollectorSender.TimeoutSettings.DEFAULT_TERMINATION_TIMEOUT) final long terminationTimeout,
@PluginAttribute(value = "call_timeout") final long callTimeout,
@PluginAttribute(value = "read_timeout") final long readTimeout,
@PluginAttribute(value = "write_timeout") final long writeTimeout,
@PluginAttribute(value = "termination_timeout") final long terminationTimeout,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand Down Expand Up @@ -93,7 +93,7 @@
* properties file.
*/
public final class HttpEventCollectorLoggingHandler extends Handler {
private HttpEventCollectorSender sender = null;
private HttpEventCollectorSender sender;
private final String IncludeLoggerNameConfTag = "include_logger_name";
private final boolean includeLoggerName;
private final String IncludeThreadNameConfTag = "include_thread_name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand Down Expand Up @@ -38,16 +38,16 @@ public class HttpEventCollectorMiddleware {
* An interface that describes an abstract events sender working asynchronously.
*/
public interface IHttpSender {
public void postEvents(final List<HttpEventCollectorEventInfo> events,
IHttpSenderCallback callback);
void postEvents(final List<HttpEventCollectorEventInfo> events,
IHttpSenderCallback callback);
}

/**
* Callback methods invoked by events sender.
*/
public interface IHttpSenderCallback {
public void completed(int statusCode, final String reply);
public void failed(final Exception ex);
void completed(int statusCode, final String reply);
void failed(final Exception ex);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand Down Expand Up @@ -30,7 +30,7 @@
*/
public class HttpEventCollectorResendMiddleware
extends HttpEventCollectorMiddleware.HttpSenderMiddleware {
private long retriesOnError = 0;
private long retriesOnError;

/**
* Create a resend middleware component.
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/com/splunk/logging/HttpEventCollectorSender.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.splunk.logging;

/**
/*
* @copyright
*
* Copyright 2013-2015 Splunk, Inc.
Expand All @@ -27,7 +27,6 @@
import javax.net.ssl.*;
import java.io.IOException;
import java.io.Serializable;
import java.security.cert.CertificateException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -63,7 +62,7 @@ public enum SendMode
{
Sequential,
Parallel
};
}

/**
* Recommended default values for events batching.
Expand All @@ -79,7 +78,7 @@ public enum SendMode
private long maxEventsBatchCount;
private long maxEventsBatchSize;
private Timer timer;
private List<HttpEventCollectorEventInfo> eventsBatch = new LinkedList<HttpEventCollectorEventInfo>();
private List<HttpEventCollectorEventInfo> eventsBatch = new LinkedList<>();
private long eventsBatchSize = 0; // estimated total size of events batch
private static final OkHttpClient httpSharedClient = new OkHttpClient(); // shared instance with the default settings
private OkHttpClient httpClient = null; // shares the same connection pool and thread pools with the shared instance
Expand Down Expand Up @@ -354,11 +353,11 @@ private void startHttpClient() {
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}

@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}

@Override
Expand All @@ -377,12 +376,7 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
} catch (Exception ignored) { /* nop */ }

builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
builder.hostnameVerifier((hostname, session) -> true);
}

httpClient = builder.build();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/splunk/logging/SplunkCimLogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class SplunkCimLogEvent {
* @param eventID event ID
*/
public SplunkCimLogEvent(String eventName, String eventID) {
entries = new LinkedHashMap<String, Object>();
entries = new LinkedHashMap<>();

addField(PREFIX_NAME, eventName);
addField(PREFIX_EVENT_ID, eventID);
Expand Down Expand Up @@ -157,7 +157,7 @@ public String toString() {
private static final String THROWABLE_MESSAGE = "throwable_message";
private static final String THROWABLE_STACKTRACE_ELEMENTS = "stacktrace_elements";

/**
/*
* Splunk Common Information Model(CIM) Fields
*/

Expand Down
21 changes: 6 additions & 15 deletions src/main/java/com/splunk/logging/TcpAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,7 @@ private SocketConnector initSocketConnector() {
connector = getDefaultSocketConnectorConstr().newInstance(address, port, 0, reconnectionDelay);
}

catch (InvocationTargetException e) {
throwRuntimeException(e);
}
catch (InstantiationException e) {
throwRuntimeException(e);
}
catch (IllegalAccessException e) {
catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
throwRuntimeException(e);
}

Expand Down Expand Up @@ -243,14 +237,11 @@ public void start() {

// Dispatch this instance of the appender.
if (!errorPresent) {
queue = queueSize <= 0 ? new SynchronousQueue<ILoggingEvent>() : new ArrayBlockingQueue<ILoggingEvent>(queueSize);
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, "splunk-tcp-appender");
t.setDaemon(true);
return t;
}
queue = queueSize <= 0 ? new SynchronousQueue<>() : new ArrayBlockingQueue<>(queueSize);
ThreadFactory factory = r -> {
Thread t = new Thread(r, "splunk-tcp-appender");
t.setDaemon(true);
return t;
};
executor = Executors.newSingleThreadExecutor(factory);
executor.execute(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.splunk.logging.serialization;

import com.google.gson.*;
import com.splunk.logging.EventBodySerializer;
import com.splunk.logging.HttpEventCollectorEventInfo;

import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.splunk.logging.hec.MetadataTags;

import java.util.*;
import java.util.stream.Collectors;

public class HecJsonSerializer {
private static final Set<String> KEYWORDS = MetadataTags.HEC_TAGS;
Expand Down