diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java index b2085821ea21ee251891e3e1cb978229ae6d7e22..87b27aa822de676fefd31bf8647cddb2b8f4837c 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -229,7 +229,11 @@ public class ColorSchemaReader { } } if (colorColumn != null) { - schema.setColor(colorParser.parse(values[colorColumn])); + try { + schema.setColor(colorParser.parse(values[colorColumn])); + } catch (InvalidArgumentException e) { + throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e); + } } if (identifierColumn != null && !values[identifierColumn].equals("")) { processGeneralIdentifier(values[identifierColumn], schema, errorPrefix); @@ -535,7 +539,11 @@ public class ColorSchemaReader { schema.setValue(parseValueColumn(values[valueColumn], errorPrefix)); } if (colorColumn != null && !values[colorColumn].isEmpty()) { - schema.setColor(colorParser.parse(values[colorColumn])); + try { + schema.setColor(colorParser.parse(values[colorColumn])); + } catch (InvalidArgumentException e) { + throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e); + } } if (schema.getValue() != null && schema.getColor() != null) { throw new InvalidColorSchemaException(errorPrefix + "Either color or value can be defined but found both"); diff --git a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java index 8f38ead287c120fe84ebf7d78c168c6328a9d200..20d037fa246c3913db34fd8cfdfc48b99fb134a6 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -378,6 +378,23 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { } } + @Test + public void testColoringWithEmptyColor() throws Exception { + try { + ColorSchemaReader reader = new ColorSchemaReader(); + Map<String, String> params = new HashMap<>(); + params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3"); + + String input = "name\tcolor\ns1\tx"; + reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params); + fail("Exception expected"); + } catch (InvalidColorSchemaException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testColoringWithInvalidValueAndColor2() throws Exception { try {