Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.graylog.plugins.pipelineprocessor.ast.expressions;

import org.antlr.v4.runtime.Token;
import org.graylog.plugins.pipelineprocessor.parser.ParseException;
import org.graylog.plugins.pipelineprocessor.parser.errors.SyntaxError;

import java.util.Collections;

Expand All @@ -26,7 +28,19 @@ public abstract class UnaryExpression extends BaseExpression {

public UnaryExpression(Token start, Expression right) {
super(start);
this.right = right;
this.right = requireNonNull(right, start);
}

private static Expression requireNonNull(Expression expression, Token token) {
if (expression != null) {
return expression;
} else {
final int line = token.getLine();
final int positionInLine = token.getCharPositionInLine();
final String msg = "Invalid expression (line: " + line + ", column: " + positionInLine + ")";
final SyntaxError syntaxError = new SyntaxError(token.getText(), line, positionInLine, msg, null);
throw new ParseException(Collections.singleton(syntaxError));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;

import javax.annotation.Nullable;

public class SyntaxError extends ParseError {

private final Object offendingSymbol;
Expand All @@ -28,7 +30,7 @@ public class SyntaxError extends ParseError {
private final String msg;
private final RecognitionException e;

public SyntaxError(Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
public SyntaxError(@Nullable Object offendingSymbol, int line, int charPositionInLine, String msg, @Nullable RecognitionException e) {
super("syntax_error", new ParserRuleContext());

this.offendingSymbol = offendingSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

import org.graylog.plugins.pipelineprocessor.BaseParserTest;
import org.graylog.plugins.pipelineprocessor.EvaluationContext;
import org.graylog.plugins.pipelineprocessor.ast.Pipeline;
Expand Down Expand Up @@ -56,6 +55,7 @@
import org.graylog.plugins.pipelineprocessor.parser.errors.NonIndexableType;
import org.graylog.plugins.pipelineprocessor.parser.errors.OptionalParametersMustBeNamed;
import org.graylog.plugins.pipelineprocessor.parser.errors.ParseError;
import org.graylog.plugins.pipelineprocessor.parser.errors.SyntaxError;
import org.graylog.plugins.pipelineprocessor.parser.errors.UndeclaredFunction;
import org.graylog.plugins.pipelineprocessor.parser.errors.UndeclaredVariable;
import org.graylog2.plugin.InstantMillisProvider;
Expand Down Expand Up @@ -413,6 +413,17 @@ public void invalidDateAddition() {
}
}

@Test
public void issue185() {
try {
parseRuleWithOptionalCodegen();
fail("Should have thrown parse exception");
} catch (ParseException e) {
assertEquals(1, e.getErrors().size());
assertEquals(SyntaxError.class, Iterables.getOnlyElement(e.getErrors()).getClass());
}
}


public static class CustomObject {
private final String id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rule "issue-185"
when
true
then
let a = "\s+$"
end