Skip to content

Commit

Permalink
Prevent NPEs
Browse files Browse the repository at this point in the history
  • Loading branch information
bpross-52n committed Oct 16, 2024
1 parent 1790df0 commit d8e87bb
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ public String validatePositionQueryUsingParameters(Set<String> collectionIds, St
List<String> crsList = jsonResponse.getList("crs");

String supportedCRS = null;
for (int q = 0; q < crsList.size(); q++) {
if (crsList.get(q).equals("CRS:84") ||
crsList.get(q).equals("CRS84") ||
crsList.get(q).equals("EPSG:4326") ||
crsList.get(q).contains("www.opengis.net/def/crs/OGC/1.3/CRS84")) {
supportedCRS = crsList.get(q);
if(crsList != null) {
for (int q = 0; q < crsList.size(); q++) {
if (crsList.get(q).equals("CRS:84") ||
crsList.get(q).equals("CRS84") ||
crsList.get(q).equals("EPSG:4326") ||
crsList.get(q).contains("www.opengis.net/def/crs/OGC/1.3/CRS84")) {
supportedCRS = crsList.get(q);
}
}
}
if (supportedCRS == null) {
Expand All @@ -79,14 +81,19 @@ public String validatePositionQueryUsingParameters(Set<String> collectionIds, St
HashMap positionQuery = (HashMap) dataQueries.get("position");
HashMap link = (HashMap) positionQuery.get("link");
HashMap variables = (HashMap) link.get("variables");
ArrayList<String> outputFormatList = (ArrayList<String>) variables.get("output_formats");
String supportedFormat = null;
for (int f = 0; f < outputFormatList.size(); f++) {
if (outputFormatList.get(f).equals("CoverageJSON") || outputFormatList.get(f).contains("CoverageJSON")) { //preference for CoverageJSON if supported
supportedFormat = outputFormatList.get(f);
}
else if (outputFormatList.get(f).equals("GeoJSON")) {
supportedFormat = outputFormatList.get(f);

if(variables==null) { //Avoids Nullpointer Exception
sb.append(" The variables element is missing from the collection "+collectionId+" .");
} else {
ArrayList<String> outputFormatList = (ArrayList<String>) variables.get("output_formats");
for (int f = 0; f < outputFormatList.size(); f++) {
if (outputFormatList.get(f).equals("CoverageJSON") || outputFormatList.get(f).contains("CoverageJSON")) { //preference for CoverageJSON if supported
supportedFormat = outputFormatList.get(f);
}
else if (outputFormatList.get(f).equals("GeoJSON")) {
supportedFormat = outputFormatList.get(f);
}
}
}

Expand Down

0 comments on commit d8e87bb

Please sign in to comment.