Skip to content

Commit

Permalink
Fixed issue with NPE in CSSWatcher caused by race condition - CSS wat…
Browse files Browse the repository at this point in the history
…cher launched before JavaSEPort had been instantiated. #3590
  • Loading branch information
shannahcloudbeds committed May 11, 2022
1 parent bd7e574 commit 1beb5de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Ports/JavaSE/src/com/codename1/impl/javase/CSSWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void run() {
System.out.println("Watching CSS files for changes: ["+overrideInputs+"]");
}
}
File resDir = JavaSEPort.instance.getSourceResourcesDir();
File resDir = JavaSEPort.getSourceResourcesDir();

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

Expand Down
32 changes: 14 additions & 18 deletions Ports/JavaSE/src/com/codename1/impl/javase/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,7 @@ public Object invoke(Object o, Method method, Object[] os) throws Throwable {
}

setProxySettings();
if (CSSWatcher.isSupported()) {
// Delay the starting of the CSS watcher to avoid compiling the CSS file while the theme is being loaded.
Timer t = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
CSSWatcher cssWatcher = new CSSWatcher();
cssWatcher.start();
}
};
t.schedule(tt, 2000);

}

final Properties p = new Properties();
String currentDir = System.getProperty("user.dir");
File props = new File(currentDir, "codenameone_settings.properties");
Expand All @@ -235,11 +222,7 @@ public void run() {
} catch (IOException ex) {
}
}






} else {
System.out.println("Cannot find codenameone_settings.properties at "+props);
}
Expand Down Expand Up @@ -289,6 +272,19 @@ public void run() {
CodenameOneImplementation.setPurchaseCallback((PurchaseCallback)app);
}
Display.init(null);
if (CSSWatcher.isSupported()) {
// Delay the starting of the CSS watcher to avoid compiling the CSS file while the theme is being loaded.
Timer t = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
CSSWatcher cssWatcher = new CSSWatcher();
cssWatcher.start();
}
};
t.schedule(tt, 2000);

}

//if (isDebug && usingHotswapAgent) {
if (MavenUtils.isRunningInMaven() && MavenUtils.isRunningInJDK()) {
Expand Down
4 changes: 2 additions & 2 deletions Ports/JavaSE/src/com/codename1/impl/javase/JavaSEPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -13593,11 +13593,11 @@ public Boolean canExecute(String url) {
}


public File getCWD() {
public static File getCWD() {
return new File(System.getProperty("user.dir"));
}

public File getSourceResourcesDir() {
public static File getSourceResourcesDir() {
File resDir = new File(getCWD(), "src" + File.separator + "main" + File.separator + "resources");
if (!resDir.exists()) {
resDir = new File(getCWD(), "src");
Expand Down
21 changes: 1 addition & 20 deletions Ports/JavaSE/src/com/codename1/impl/javase/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ private static void loadSimulatorProperties(File projectDir) {

}


private static void setCWD() {
try {
File currDir = new File(System.getProperty("user.dir")).getCanonicalFile();
File codenameOneSettings = new File(currDir, "codenameone_settings.properties");
if (codenameOneSettings.exists()) {
return;
}
currDir = new File(currDir, "common");
codenameOneSettings = new File(currDir, codenameOneSettings.getName());
if (codenameOneSettings.exists()) {
System.setProperty("user.dir", currDir.getAbsolutePath());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}

/**
* Accepts the classname to launch
*/
Expand Down Expand Up @@ -128,8 +110,7 @@ public static void main(final String[] argv) throws Exception {
if (System.getenv("CN1_SIMULATOR_SKIN") != null) {
System.setProperty("skin", System.getenv("CN1_SIMULATOR_SKIN"));
}



String classPathStr = System.getProperty("java.class.path");
if (System.getProperty("cn1.class.path") != null) {
classPathStr += File.pathSeparator + System.getProperty("cn1.class.path");
Expand Down

0 comments on commit 1beb5de

Please sign in to comment.