Skip to content

Commit

Permalink
Fix PostgresIndexQueryBuilder null pointer exception (#116)
Browse files Browse the repository at this point in the history
* Throw IllegalArgumentException when query string does not match regex

* Unit test for exception
  • Loading branch information
omadaan authored Apr 3, 2024
1 parent 1fc1916 commit cc5f8c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public Condition(String query) {
if (this.attribute.endsWith("_time")) {
values.set(0, millisToUtc(values.get(0)));
}
} else {
throw new IllegalArgumentException("Incorrectly formatted query string: " + query);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.netflix.conductor.postgres.config.PostgresProperties;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;

public class PostgresIndexQueryBuilderTest {
Expand Down Expand Up @@ -288,4 +289,19 @@ void shouldAllowJsonSearch() throws SQLException {
"SELECT json_data::TEXT FROM table_name WHERE json_data @> ?::JSONB LIMIT ? OFFSET ?";
assertEquals(expectedQuery, builder.getQuery());
}

@Test()
void shouldThrowIllegalArgumentExceptionWhenQueryStringIsInvalid() {
String inputQuery =
"workflowType IN (one,two) AND status IN (COMPLETED,RUNNING) AND startTime>1675701498000 AND xyz";

try {
new PostgresIndexQueryBuilder(
"table_name", inputQuery, "", 0, 15, new ArrayList<>(), properties);

fail("should have failed since xyz does not conform to expected format");
} catch (IllegalArgumentException e) {
assertEquals("Incorrectly formatted query string: xyz", e.getMessage());
}
}
}

0 comments on commit cc5f8c0

Please sign in to comment.