From 57efdec7570b37258639ac0b0d95e7c0d5e70233 Mon Sep 17 00:00:00 2001 From: Al Niessner Date: Wed, 4 Mar 2026 11:44:39 -0800 Subject: [PATCH 1/4] always check field name Check that given field name in the query language is valid throwing same error when they do not. --- .../registry/model/Antlr4SearchListener.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java index 12122afc..85d21171 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java @@ -73,16 +73,17 @@ public void exitFields(SearchParser.FieldsContext ctx) { if (ctx.ANY() != null) { fieldname = ctx.ANY().getText(); } - if (fieldname.contains("*")) { - if (this.knownFieldNames.isEmpty()) { - try { - for (PropertiesListInner property : ProductsController.productPropertiesList(this.connectionContext).getBody()) { - this.knownFieldNames.add(property.getProperty()); - } - } catch (OpenSearchException | IOException e) { - log.error("Could not load the mapping(s) from opensearch; meaning 'wildcarding' will not work", e); + if (this.knownFieldNames.isEmpty()) { + try { + for (PropertiesListInner property : ProductsController.productPropertiesList(this.connectionContext).getBody()) { + this.knownFieldNames.add(property.getProperty()); } + } catch (OpenSearchException | IOException e) { + log.error("Could not load the mapping(s) from opensearch; meaning 'wildcarding' will not work", e); + throw new ParseCancellationException("Could not load the LDD field names from opensearch."); } + } + if (fieldname.contains("*")) { String theKey = fieldname.replace(".", "\\.").replace("*", ".*"); Pattern regex = Pattern.compile(theKey); for (String fn : this.knownFieldNames.stream() @@ -94,7 +95,12 @@ public void exitFields(SearchParser.FieldsContext ctx) { throw new ParseCancellationException("Wildcarding request '" + fieldname + "' cannot match any field names in the LDD using regular expression " + theKey); } } else { - this.fieldNames.add(SearchUtil.jsonPropertyToOpenProperty(fieldname)); + String fn = SearchUtil.jsonPropertyToOpenProperty(fieldname); + if (this.fieldNames.contains(fn) ) { + this.fieldNames.add(fn); + } else { + throw new ParseCancellationException("The request '" + fieldname + "' does match any field names in the LDD."); + } } this.isAnyWildcard = ctx.ALL() == null && this.fieldNames.size() > 1; } From 747a00787ec95a9651632d0621f06ed19be7cc80 Mon Sep 17 00:00:00 2001 From: al-niessner <1130658+al-niessner@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:55:15 -0700 Subject: [PATCH 2/4] Update Antlr4SearchListener.java change requested --- .../gov/nasa/pds/api/registry/model/Antlr4SearchListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java index 85d21171..407d65fe 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java @@ -80,7 +80,7 @@ public void exitFields(SearchParser.FieldsContext ctx) { } } catch (OpenSearchException | IOException e) { log.error("Could not load the mapping(s) from opensearch; meaning 'wildcarding' will not work", e); - throw new ParseCancellationException("Could not load the LDD field names from opensearch."); + throw new RuntimeException("Could not load the LDD field names from opensearch.", e); } } if (fieldname.contains("*")) { From 3cfe7c350d6482f2fb8c3585186554b35b89ac21 Mon Sep 17 00:00:00 2001 From: al-niessner <1130658+al-niessner@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:03:54 -0700 Subject: [PATCH 3/4] Update Antlr4SearchListener.java sonarqube made me do it --- .../gov/nasa/pds/api/registry/model/Antlr4SearchListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java index 407d65fe..e4af293a 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java @@ -8,6 +8,7 @@ import gov.nasa.pds.api.registry.lexer.SearchParser; import gov.nasa.pds.model.PropertiesListInner; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; @@ -79,8 +80,7 @@ public void exitFields(SearchParser.FieldsContext ctx) { this.knownFieldNames.add(property.getProperty()); } } catch (OpenSearchException | IOException e) { - log.error("Could not load the mapping(s) from opensearch; meaning 'wildcarding' will not work", e); - throw new RuntimeException("Could not load the LDD field names from opensearch.", e); + throw new UncheckedIOException("Could not load the mapping(s) from opensearch; meaning 'q=' with field names will not work", e); } } if (fieldname.contains("*")) { From 403dec41a832312aded9c500a85b4823e482f53e Mon Sep 17 00:00:00 2001 From: al-niessner <1130658+al-niessner@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:09:22 -0700 Subject: [PATCH 4/4] Update Antlr4SearchListener.java silly sonarqube is just making the code worse not better. runtimeexception is the correct answer, but this holds truth in that if the state of the system is not repaired, the same error will continue to occur. --- .../gov/nasa/pds/api/registry/model/Antlr4SearchListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java index e4af293a..196c7749 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/Antlr4SearchListener.java @@ -8,7 +8,6 @@ import gov.nasa.pds.api.registry.lexer.SearchParser; import gov.nasa.pds.model.PropertiesListInner; import java.io.IOException; -import java.io.UncheckedIOException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; @@ -80,7 +79,7 @@ public void exitFields(SearchParser.FieldsContext ctx) { this.knownFieldNames.add(property.getProperty()); } } catch (OpenSearchException | IOException e) { - throw new UncheckedIOException("Could not load the mapping(s) from opensearch; meaning 'q=' with field names will not work", e); + throw new IllegalStateException("Could not load the mapping(s) from opensearch; meaning 'q=' with field names will not work", e); } } if (fieldname.contains("*")) {