Skip to content

Commit cc6ba38

Browse files
authored
Merge pull request #444 from avinxshKD/fix/java-init-and-param-parser
fix: java init stuck in main and param parser broken for values with =
2 parents 3f1c744 + 1136c26 commit cc6ba38

1 file changed

Lines changed: 35 additions & 32 deletions

File tree

concoredocker.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,61 @@ public class concoredocker {
2828
private static double simtime = 0;
2929
private static double maxtime;
3030

31-
public static void main(String[] args) {
31+
// initialize on class load, same as Python module-level init
32+
static {
3233
try {
3334
iport = parseFile("concore.iport");
3435
} catch (IOException e) {
35-
e.printStackTrace();
3636
}
3737
try {
3838
oport = parseFile("concore.oport");
3939
} catch (IOException e) {
40-
e.printStackTrace();
4140
}
42-
4341
try {
4442
String sparams = new String(Files.readAllBytes(Paths.get(inpath + "1/concore.params")), java.nio.charset.StandardCharsets.UTF_8);
4543
if (sparams.length() > 0 && sparams.charAt(0) == '"') { // windows keeps "" need to remove
4644
sparams = sparams.substring(1);
4745
sparams = sparams.substring(0, sparams.indexOf('"'));
4846
}
49-
// Try parsing as dict literal first (matches Python parse_params logic)
50-
sparams = sparams.trim();
51-
if (sparams.startsWith("{") && sparams.endsWith("}")) {
52-
try {
53-
Object parsed = literalEval(sparams);
54-
if (parsed instanceof Map) {
55-
@SuppressWarnings("unchecked")
56-
Map<String, Object> parsedMap = (Map<String, Object>) parsed;
57-
params = parsedMap;
58-
}
59-
} catch (Exception e) {
60-
System.out.println("bad params: " + sparams);
47+
params = parseParams(sparams);
48+
} catch (IOException e) {
49+
params = new HashMap<>();
50+
}
51+
defaultMaxTime(100);
52+
}
53+
54+
/**
55+
* Parses a param string into a map, matching concore_base.parse_params.
56+
* Tries dict literal first, then falls back to semicolon-separated key=value pairs.
57+
*/
58+
private static Map<String, Object> parseParams(String sparams) {
59+
Map<String, Object> result = new HashMap<>();
60+
if (sparams == null || sparams.isEmpty()) return result;
61+
String trimmed = sparams.trim();
62+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
63+
try {
64+
Object val = literalEval(trimmed);
65+
if (val instanceof Map) {
66+
@SuppressWarnings("unchecked")
67+
Map<String, Object> map = (Map<String, Object>) val;
68+
return map;
6169
}
62-
} else if (!sparams.isEmpty()) {
63-
// Fallback: convert key=value,key=value format to dict
64-
System.out.println("converting sparams: " + sparams);
65-
sparams = "{'" + sparams.replaceAll(";", ",'").replaceAll("=", "':").replaceAll(" ", "") + "}";
66-
System.out.println("converted sparams: " + sparams);
70+
} catch (Exception e) {
71+
}
72+
}
73+
for (String item : trimmed.split(";")) {
74+
if (item.contains("=")) {
75+
String[] parts = item.split("=", 2); // split on first '=' only
76+
String key = parts[0].trim();
77+
String value = parts[1].trim();
6778
try {
68-
Object parsed = literalEval(sparams);
69-
if (parsed instanceof Map) {
70-
@SuppressWarnings("unchecked")
71-
Map<String, Object> parsedMap = (Map<String, Object>) parsed;
72-
params = parsedMap;
73-
}
79+
result.put(key, literalEval(value));
7480
} catch (Exception e) {
75-
System.out.println("bad params: " + sparams);
81+
result.put(key, value);
7682
}
7783
}
78-
} catch (IOException e) {
79-
params = new HashMap<>();
8084
}
81-
82-
defaultMaxTime(100);
85+
return result;
8386
}
8487

8588
/**

0 commit comments

Comments
 (0)