Skip to content

Commit 1beb5de

Browse files
Fixed issue with NPE in CSSWatcher caused by race condition - CSS watcher launched before JavaSEPort had been instantiated. #3590
1 parent bd7e574 commit 1beb5de

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void run() {
187187
System.out.println("Watching CSS files for changes: ["+overrideInputs+"]");
188188
}
189189
}
190-
File resDir = JavaSEPort.instance.getSourceResourcesDir();
190+
File resDir = JavaSEPort.getSourceResourcesDir();
191191

192192
File destFile = new File(resDir, "theme.res");
193193

Ports/JavaSE/src/com/codename1/impl/javase/Executor.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,7 @@ public Object invoke(Object o, Method method, Object[] os) throws Throwable {
197197
}
198198

199199
setProxySettings();
200-
if (CSSWatcher.isSupported()) {
201-
// Delay the starting of the CSS watcher to avoid compiling the CSS file while the theme is being loaded.
202-
Timer t = new Timer();
203-
TimerTask tt = new TimerTask() {
204-
@Override
205-
public void run() {
206-
CSSWatcher cssWatcher = new CSSWatcher();
207-
cssWatcher.start();
208-
}
209-
};
210-
t.schedule(tt, 2000);
211200

212-
}
213-
214201
final Properties p = new Properties();
215202
String currentDir = System.getProperty("user.dir");
216203
File props = new File(currentDir, "codenameone_settings.properties");
@@ -235,11 +222,7 @@ public void run() {
235222
} catch (IOException ex) {
236223
}
237224
}
238-
239-
240-
241-
242-
225+
243226
} else {
244227
System.out.println("Cannot find codenameone_settings.properties at "+props);
245228
}
@@ -289,6 +272,19 @@ public void run() {
289272
CodenameOneImplementation.setPurchaseCallback((PurchaseCallback)app);
290273
}
291274
Display.init(null);
275+
if (CSSWatcher.isSupported()) {
276+
// Delay the starting of the CSS watcher to avoid compiling the CSS file while the theme is being loaded.
277+
Timer t = new Timer();
278+
TimerTask tt = new TimerTask() {
279+
@Override
280+
public void run() {
281+
CSSWatcher cssWatcher = new CSSWatcher();
282+
cssWatcher.start();
283+
}
284+
};
285+
t.schedule(tt, 2000);
286+
287+
}
292288

293289
//if (isDebug && usingHotswapAgent) {
294290
if (MavenUtils.isRunningInMaven() && MavenUtils.isRunningInJDK()) {

Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13593,11 +13593,11 @@ public Boolean canExecute(String url) {
1359313593
}
1359413594

1359513595

13596-
public File getCWD() {
13596+
public static File getCWD() {
1359713597
return new File(System.getProperty("user.dir"));
1359813598
}
1359913599

13600-
public File getSourceResourcesDir() {
13600+
public static File getSourceResourcesDir() {
1360113601
File resDir = new File(getCWD(), "src" + File.separator + "main" + File.separator + "resources");
1360213602
if (!resDir.exists()) {
1360313603
resDir = new File(getCWD(), "src");

Ports/JavaSE/src/com/codename1/impl/javase/Simulator.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,6 @@ private static void loadSimulatorProperties(File projectDir) {
8181

8282
}
8383

84-
85-
private static void setCWD() {
86-
try {
87-
File currDir = new File(System.getProperty("user.dir")).getCanonicalFile();
88-
File codenameOneSettings = new File(currDir, "codenameone_settings.properties");
89-
if (codenameOneSettings.exists()) {
90-
return;
91-
}
92-
currDir = new File(currDir, "common");
93-
codenameOneSettings = new File(currDir, codenameOneSettings.getName());
94-
if (codenameOneSettings.exists()) {
95-
System.setProperty("user.dir", currDir.getAbsolutePath());
96-
}
97-
} catch (IOException ex) {
98-
ex.printStackTrace();
99-
}
100-
}
101-
10284
/**
10385
* Accepts the classname to launch
10486
*/
@@ -128,8 +110,7 @@ public static void main(final String[] argv) throws Exception {
128110
if (System.getenv("CN1_SIMULATOR_SKIN") != null) {
129111
System.setProperty("skin", System.getenv("CN1_SIMULATOR_SKIN"));
130112
}
131-
132-
113+
133114
String classPathStr = System.getProperty("java.class.path");
134115
if (System.getProperty("cn1.class.path") != null) {
135116
classPathStr += File.pathSeparator + System.getProperty("cn1.class.path");

0 commit comments

Comments
 (0)