From 0dc9ee680eaad8cd16a26c06b2d9f92b7487f82b Mon Sep 17 00:00:00 2001 From: John Buck Date: Sun, 23 Jun 2024 16:40:57 -0400 Subject: [PATCH] i_232 Fix deserialization issue If an older Language object is deserialized, the extensions array can be null. This fix addresses that. --- src/edu/csus/ecs/pc2/core/model/Language.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/edu/csus/ecs/pc2/core/model/Language.java b/src/edu/csus/ecs/pc2/core/model/Language.java index 8fd3b939d..d88409c3b 100644 --- a/src/edu/csus/ecs/pc2/core/model/Language.java +++ b/src/edu/csus/ecs/pc2/core/model/Language.java @@ -245,6 +245,15 @@ public int hashCode() { return elementId.hashCode(); } + /** + * Check if extensions array is allocated. If not allocate it. This can happen on deserialization of an older object. + */ + private void checkExtensions() { + if(extensions == null) { + extensions = new ArrayList(); + } + } + public String getExecutableIdentifierMask() { return executableIdentifierMask; } @@ -282,7 +291,8 @@ public boolean isUsingJudgeProgramExecuteCommandLine() { } public void setID(String newId) { - this.id = newId; + id = newId; + checkExtensions(); // set default extensions for the language based on its CLICS id if(extensions.isEmpty()) { String [] ext = null; @@ -308,14 +318,36 @@ public String getID() { } public void setExtensions(ArrayList exts) { + checkExtensions(); extensions.clear(); extensions.addAll(exts); } public ArrayList getExtensions() { + checkExtensions(); + if(extensions.isEmpty()) { + setDefaultExtensions(); + } return(extensions); } + /** + * In the event the user did not specify a CLICS ID for the language, we have to make a guess. + * We use is the lower-case display name, minus spaces, and + changed to p, and compare to our known + * list of CLICS ids. + */ + private void setDefaultExtensions() + { + // Make lower case, get rid of spaces and convert all plus signs to p's (eg c++ -> cpp) + String fauxId = getDisplayName().toLowerCase().replaceAll("\\s", "").replaceAll("\\+", "p"); + // Let's use it as the clics ID + setID(fauxId); + // if it didn't work, then pretend we didn't try. + if(extensions.isEmpty()) { + id = null; + } + } + /** * Utility method to convert between a string array and ArrayList *