Skip to content

Commit

Permalink
i_232 Fix deserialization issue
Browse files Browse the repository at this point in the history
If an older Language object is deserialized, the extensions array can be null.  This fix addresses that.
  • Loading branch information
johnbrvc committed Jul 2, 2024
1 parent 679d19c commit 0dc9ee6
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/edu/csus/ecs/pc2/core/model/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>();
}
}

public String getExecutableIdentifierMask() {
return executableIdentifierMask;
}
Expand Down Expand Up @@ -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;
Expand All @@ -308,14 +318,36 @@ public String getID() {
}

public void setExtensions(ArrayList<String> exts) {
checkExtensions();
extensions.clear();
extensions.addAll(exts);
}

public ArrayList<String> 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<String>
*
Expand Down

0 comments on commit 0dc9ee6

Please sign in to comment.