Skip to content

Commit a02d8e3

Browse files
author
zhourenjian
committed
Fixed bug that AClass.loadClass can not accept null Runnable instance.
1 parent 8769474 commit a02d8e3

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/AClass.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ protected AClass() {
4545
*
4646
* @j2sNativeSrc
4747
* ClazzLoader.loadClass (clazzName, function () {
48-
* if (Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
48+
* if (afterLoaded != null && Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
4949
* var clz = Clazz.evalType (clazzName);
5050
* afterLoaded.setClazz (clz);
5151
* }
52-
* afterLoaded.run ();
52+
* if (afterLoaded != null) afterLoaded.run ();
5353
* }, false, true);
5454
* @j2sNative
5555
* ClazzLoader.loadClass (a, function () {
56-
* if (Clazz.instanceOf (b, net.sf.j2s.ajax.ARunnable)) {
56+
* if (b != null && Clazz.instanceOf (b, net.sf.j2s.ajax.ARunnable)) {
5757
* var clz = Clazz.evalType (a);
5858
* b.setClazz (clz);
5959
* }
60-
* b.run ();
60+
* if (b != null) b.run ();
6161
* }, false, true);
6262
*/
6363
public static void load(final String clazzName, final Runnable afterLoaded) {
6464
new Thread(new Runnable() {
6565
public void run() {
6666
try {
6767
Class clz = Class.forName(clazzName);
68-
if (afterLoaded instanceof ARunnable) {
68+
if (afterLoaded != null && afterLoaded instanceof ARunnable) {
6969
ARunnable runnable = (ARunnable) afterLoaded;
7070
runnable.setClazz(clz);
7171
}
7272
} catch (ClassNotFoundException e) {
7373
e.printStackTrace();
7474
return ;
7575
}
76-
afterLoaded.run();
76+
if (afterLoaded != null) afterLoaded.run();
7777
}
7878
}).start();
7979
}

sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleRPCHttpServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
230230
resp.setHeader("Pragma", "no-cache");
231231
resp.setHeader("Cache-Control", "no-cache");
232232
resp.setDateHeader("Expires", 0);
233-
resp.setContentType("text/plain;charset=utf-8");
233+
resp.setContentType("text/plain; charset=utf-8");
234234
//resp.setCharacterEncoding("utf-8");
235235
PrintWriter writer = resp.getWriter();
236236
runnable.deserialize(request);

sources/net.sf.j2s.ajax/ajaxswt/net/sf/j2s/ajax/ASWTClass.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,27 @@ public static void swtLoad(String clazzName, Runnable afterLoaded) {
8383
*
8484
* @j2sNativeSrc
8585
* ClazzLoader.loadClass (clazzName, function () {
86-
* if (Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
86+
* if (afterLoaded != null && Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
8787
* var clz = Clazz.evalType (clazzName);
8888
* afterLoaded.setClazz (clz);
8989
* }
90-
* afterLoaded.run ();
90+
* if (afterLoaded != null) afterLoaded.run ();
9191
* }, false, true);
9292
* @j2sNative
9393
* ClazzLoader.loadClass (b, function () {
94-
* if (Clazz.instanceOf (c, net.sf.j2s.ajax.ARunnable)) {
94+
* if (c != null && Clazz.instanceOf (c, net.sf.j2s.ajax.ARunnable)) {
9595
* var clz = Clazz.evalType (b);
9696
* c.setClazz (clz);
9797
* }
98-
* c.run ();
98+
* if (c != null) c.run ();
9999
* }, false, true);
100100
*/
101101
static void objectLoad(Object display, final String clazzName, final Runnable afterLoaded) {
102102
((Display) display).asyncExec(new Runnable() {
103103
public void run() {
104104
try {
105-
Class clz = Class.forName(clazzName);
106-
if (afterLoaded instanceof ARunnable) {
105+
Class clz = Class.forName(clazzName); // May freeze UI!
106+
if (afterLoaded != null && afterLoaded instanceof ARunnable) {
107107
ARunnable runnable = (ARunnable) afterLoaded;
108108
runnable.setClazz(clz);
109109
}
@@ -112,7 +112,7 @@ public void run() {
112112
return ;
113113
}
114114

115-
afterLoaded.run();
115+
if (afterLoaded != null) afterLoaded.run();
116116
}
117117
});
118118
}

0 commit comments

Comments
 (0)