Skip to content

Commit

Permalink
Fix various compiler warnings (#4634)
Browse files Browse the repository at this point in the history
* Fix various compiler warnings

* Remove bogus test

After discussing with @kroepke, `PipelineRuleParserTest#invalidArgumentValue()` should rather be removed than "fixed"
as it tries to test a functionality which hasn't been implemented.
  • Loading branch information
joschi authored and bernd committed Jun 22, 2018
1 parent 515c802 commit bd5c865
Show file tree
Hide file tree
Showing 88 changed files with 416 additions and 447 deletions.
Expand Up @@ -211,8 +211,8 @@ public enum CEFMapping {
sourceZoneURI("sourceZoneURI", "sourceZoneURI", CEFMapping::convertString);

// Lookup tables for faster access
private static final Map<String, CEFMapping> KEY_NAMES;
private static final Map<String, CEFMapping> FULL_NAMES;
private static final ImmutableMap<String, CEFMapping> KEY_NAMES;
private static final ImmutableMap<String, CEFMapping> FULL_NAMES;

static {
final ImmutableMap.Builder<String, CEFMapping> keyNamesBuilder = ImmutableMap.builder();
Expand Down Expand Up @@ -274,7 +274,6 @@ private static Integer convertType(String s) {
return convertInteger(s);
}

@Nullable
private static Integer convertDirection(String s) {
return convertInteger(s);
}
Expand Down
Expand Up @@ -40,13 +40,13 @@
import org.graylog2.plugin.lookup.LookupDataAdapterConfiguration;
import org.graylog2.plugin.lookup.LookupResult;
import org.graylog2.plugin.utilities.FileInfo;
import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.Duration;
import org.slf4j.Logger;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.IOException;
Expand Down
Expand Up @@ -74,6 +74,7 @@ public GeoIpProcessor(ClusterConfigService clusterConfigService,
eventBus.register(this);
}

@Override
public Messages process(Messages messages) {
for (Message message : messages) {
filterEngine.get().filter(message);
Expand Down
Expand Up @@ -246,7 +246,7 @@ public Result addChunk(ByteBuf buf, SocketAddress remoteAddress) {
}
}

private class TemplateBytes {
private static class TemplateBytes {
private final byte[] bytes;
private final boolean optionTemplate;

Expand Down
Expand Up @@ -16,6 +16,9 @@
*/
package org.graylog.plugins.netflow.v9;

import javax.annotation.Generated;

@Generated("Generated by Protobuf")
public final class NetFlowV9Journal {
private NetFlowV9Journal() {}
public static void registerAllExtensions(
Expand Down
Expand Up @@ -119,7 +119,7 @@ public List<EvalError> evaluationErrors() {
return evalErrors == null ? Collections.emptyList() : Collections.unmodifiableList(evalErrors);
}

public class TypedValue {
public static class TypedValue {
private final Class type;
private final Object value;

Expand Down
Expand Up @@ -52,6 +52,7 @@ public Pipeline withId(String id) {
return toBuilder().id(id).build();
}

@Override
@Memoized
public abstract int hashCode();

Expand Down Expand Up @@ -97,10 +98,8 @@ public abstract static class Builder {
public abstract Builder stages(SortedSet<Stage> stages);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Pipeline ");
sb.append("'").append(name()).append("'");
sb.append(" (").append(id()).append(")");
return sb.toString();
return "Pipeline '" + name() + "' (" + id() + ")";
}
}
Expand Up @@ -16,14 +16,12 @@
*/
package org.graylog.plugins.pipelineprocessor.ast;

import com.google.auto.value.AutoValue;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;

import com.google.auto.value.AutoValue;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.antlr.v4.runtime.CommonToken;
import org.graylog.plugins.pipelineprocessor.ast.expressions.BooleanExpression;
import org.graylog.plugins.pipelineprocessor.ast.expressions.LogicalExpression;
Expand All @@ -34,14 +32,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import javax.annotation.Nullable;

@AutoValue
public abstract class Rule {
private static final Logger LOG = LoggerFactory.getLogger(Rule.class);
Expand Down Expand Up @@ -208,11 +205,8 @@ public abstract static class Builder {
public abstract Rule build();
}


@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Rule ");
sb.append("'").append(name()).append("'");
sb.append(" (").append(id()).append(")");
return sb.toString();
return "Rule '" + name() + "' (" + id() + ")";
}
}
Expand Up @@ -105,6 +105,7 @@ public abstract static class Builder {
public abstract Builder ruleReferences(List<String> ruleRefs);
}

@Override
public String toString() {
return "Stage " + stage();
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class PipelineProcessorAuditEventTypes implements PluginAuditEventTypes {
public static final String RULE_UPDATE = NAMESPACE + "rule:update";
public static final String RULE_DELETE = NAMESPACE + "rule:delete";

private static final Set<String> EVENT_TYPES = ImmutableSet.<String>builder()
private static final ImmutableSet<String> EVENT_TYPES = ImmutableSet.<String>builder()
.add(PIPELINE_CONNECTION_UPDATE)
.add(PIPELINE_CREATE)
.add(PIPELINE_UPDATE)
Expand Down
Expand Up @@ -34,15 +34,6 @@

import com.google.common.collect.Maps;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Map;
import java.util.stream.Collectors;

import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileObject;
Expand All @@ -51,6 +42,14 @@
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.validation.constraints.NotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.Map;
import java.util.stream.Collectors;

public class InMemoryFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
private final Map<String, ByteArrayOutputStream> classBytes = Maps.newLinkedHashMap();
Expand All @@ -59,10 +58,12 @@ public InMemoryFileManager(StandardJavaFileManager fileManager) {
super(fileManager);
}

@Override
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
if (location == StandardLocation.CLASS_OUTPUT && classBytes.containsKey(className) && kind == Kind.CLASS) {
final byte[] bytes = classBytes.get(className).toByteArray();
return new SimpleJavaFileObject(URI.create(className), kind) {
@Override
@NotNull
public InputStream openInputStream() {
return new ByteArrayInputStream(bytes);
Expand All @@ -72,9 +73,11 @@ public InputStream openInputStream() {
return fileManager.getJavaFileForInput(location, className, kind);
}

@Override
@NotNull
public JavaFileObject getJavaFileForOutput(Location location, final String className, Kind kind, FileObject sibling) throws IOException {
return new SimpleJavaFileObject(URI.create(className), kind) {
@Override
@NotNull
public OutputStream openOutputStream() {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ protected String getEncodingName() {
return ENCODING_NAME;
}

@Override
protected String getName() {
return NAME;
}
Expand Down
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
Expand Down Expand Up @@ -94,15 +93,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicLong;

import javax.inject.Inject;

import static com.google.common.collect.ImmutableSortedSet.orderedBy;
import static java.util.Comparator.comparingInt;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -276,7 +275,7 @@ private class RuleAstBuilder extends RuleLangBaseListener {
private final Set<String> definedVars = Sets.newHashSet();

// this is true for nested field accesses
private Stack<Boolean> isIdIsFieldAccess = new Stack<>();
private ArrayDeque<Boolean> isIdIsFieldAccess = new ArrayDeque<>();

public RuleAstBuilder(ParseContext parseContext) {
this.parseContext = parseContext;
Expand Down Expand Up @@ -348,7 +347,7 @@ public void exitFunctionCall(RuleLangParser.FunctionCallContext ctx) {
params.stream()
.filter(p -> !p.optional())
.map(p -> givenArguments.containsKey(p.name()) ? null : p)
.filter(p -> p != null)
.filter(Objects::nonNull)
.collect(toList());
for (ParameterDescriptor param : missingParams) {
parseContext.addError(new MissingRequiredParam(ctx, function, param));
Expand Down Expand Up @@ -664,7 +663,7 @@ public void exitIndexedAccess(RuleLangParser.IndexedAccessContext ctx) {
}
}

private class RuleTypeAnnotator extends RuleLangBaseListener {
private static class RuleTypeAnnotator extends RuleLangBaseListener {
private final ParseContext parseContext;

public RuleTypeAnnotator(ParseContext parseContext) {
Expand Down Expand Up @@ -727,8 +726,9 @@ public void exitMultiplication(RuleLangParser.MultiplicationContext ctx) {
}
}

private class RuleTypeChecker extends RuleLangBaseListener {
private static class RuleTypeChecker extends RuleLangBaseListener {
private final ParseContext parseContext;
@SuppressWarnings("JdkObsolete")
StringBuffer sb = new StringBuffer();

public RuleTypeChecker(ParseContext parseContext) {
Expand Down Expand Up @@ -959,7 +959,7 @@ public boolean isSilent() {
}
}

private class PipelineAstBuilder extends RuleLangBaseListener {
private static class PipelineAstBuilder extends RuleLangBaseListener {
private final ParseContext parseContext;

public PipelineAstBuilder(ParseContext parseContext) {
Expand Down
Expand Up @@ -147,7 +147,7 @@ public class AuditEventTypes implements PluginAuditEventTypes {
public static final String USER_PREFERENCES_UPDATE = PREFIX + "user_preferences:update";
public static final String USER_UPDATE = PREFIX + "user:update";

private static final Set<String> EVENT_TYPES = ImmutableSet.<String>builder()
private static final ImmutableSet<String> EVENT_TYPES = ImmutableSet.<String>builder()
.add(ALARM_CALLBACK_CREATE)
.add(ALARM_CALLBACK_DELETE)
.add(ALARM_CALLBACK_UPDATE)
Expand Down
Expand Up @@ -219,7 +219,7 @@ protected Level setupLogger() {
logLevel = Level.DEBUG;

// Enable logging for Netty when running in debug mode.
InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
} else if (onlyLogErrors()) {
logLevel = Level.ERROR;
} else {
Expand Down

0 comments on commit bd5c865

Please sign in to comment.