Skip to content

Commit 3352042

Browse files
committed
fix for obscure issue with Interface
In this case, there is an Interface (TView) that WorldTView implements. But that interface, in its static initializer, creates a WorldTViewIcon by referencing a static field in WorldTView, protected static final Icon WORLDVIEW_ICON = Tracker.getResourceIcon("axes.gif", true); Ah, but this is happening before WorldView is fully initialized, and it causes WorldTView to instantiate all its static fields. OK, but then later, the JavaScript classloader runs the method that generates all the defaults for the static fields, and that was nulling out the array that had just been made.
1 parent c410841 commit 3352042

7 files changed

Lines changed: 42 additions & 36 deletions

File tree

75 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210813152700
1+
20210816185322
75 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210813152700
1+
20210816185322
75 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 2021.08.16 fix for Interface initalizing its subclass with static initialization
1011
// BH 2021.07.28 String.instantialize upgraded to use TextDecoder() if possible (not in MSIE)
1112
// BH 2021.07.20 Date.toString() format yyyy moved to end, as in Java
1213
// BH 2021.06.11 Number.compareTo(....) missing
@@ -394,7 +395,7 @@ var initStatic = function(cl, impls) {
394395
} else if (cl.superclazz) {
395396
initStatic(cl.superclazz);
396397
}
397-
cl.$static$ && cl.$static$();
398+
cl.$static$ && (initStatics(cl), cl.$static$());
398399
}
399400

400401
/**
@@ -462,11 +463,13 @@ var initClass0 = function(c) {
462463
var fields = c.$fields$;
463464
var objects = fields && fields[0];
464465
createDefaults(c, objects, false);
465-
if (!fields)
466-
return;
467-
var statics = fields[1];
466+
fields && initStatics(c);
467+
}
468+
469+
var initStatics = function(c) {
470+
var statics = c.$fields$ && c.$fields$[1];
468471
if (statics && statics.length)
469-
createDefaults(c, statics, true);
472+
createDefaults(c, statics, true);
470473
}
471474

472475
//C$.$fields$=[
@@ -477,20 +480,20 @@ var createDefaults = function(c, data, isStatic) {
477480
var a = getFields(c, data, true);
478481
if (isStatic) {
479482
for (var i = a.length; --i >= 0;) {
480-
c[a[i][0]] = a[i][1];
483+
var j = a[i][0];
484+
if (c[j] != undefined)
485+
return;
486+
c[j] = a[i][1];
481487
}
482-
} else {
483-
c.$init0$ =
484-
//(function(cs, a) {return
485-
function(){
486-
var cs = c.superclazz;
487-
cs && cs.$init0$ && cs.$init0$.apply(this);
488-
for (var i = a.length; --i >= 0;){
489-
this[a[i][0]] = a[i][1];
490-
}
491-
};
492-
// })(c.superclazz, a);
488+
return;
493489
}
490+
c.$init0$ = function(){
491+
var cs = c.superclazz;
492+
cs && cs.$init0$ && cs.$init0$.apply(this);
493+
for (var i = a.length; --i >= 0;){
494+
this[a[i][0]] = a[i][1];
495+
}
496+
};
494497

495498
}
496499

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14022,6 +14022,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
1402214022

1402314023
// Google closure compiler cannot handle Clazz.new or Clazz.super
1402414024

14025+
// BH 2021.08.16 fix for Interface initalizing its subclass with static initialization
1402514026
// BH 2021.07.28 String.instantialize upgraded to use TextDecoder() if possible (not in MSIE)
1402614027
// BH 2021.07.20 Date.toString() format yyyy moved to end, as in Java
1402714028
// BH 2021.06.11 Number.compareTo(....) missing
@@ -14409,7 +14410,7 @@ var initStatic = function(cl, impls) {
1440914410
} else if (cl.superclazz) {
1441014411
initStatic(cl.superclazz);
1441114412
}
14412-
cl.$static$ && cl.$static$();
14413+
cl.$static$ && (initStatics(cl), cl.$static$());
1441314414
}
1441414415

1441514416
/**
@@ -14477,11 +14478,13 @@ var initClass0 = function(c) {
1447714478
var fields = c.$fields$;
1447814479
var objects = fields && fields[0];
1447914480
createDefaults(c, objects, false);
14480-
if (!fields)
14481-
return;
14482-
var statics = fields[1];
14481+
fields && initStatics(c);
14482+
}
14483+
14484+
var initStatics = function(c) {
14485+
var statics = c.$fields$ && c.$fields$[1];
1448314486
if (statics && statics.length)
14484-
createDefaults(c, statics, true);
14487+
createDefaults(c, statics, true);
1448514488
}
1448614489

1448714490
//C$.$fields$=[
@@ -14492,20 +14495,20 @@ var createDefaults = function(c, data, isStatic) {
1449214495
var a = getFields(c, data, true);
1449314496
if (isStatic) {
1449414497
for (var i = a.length; --i >= 0;) {
14495-
c[a[i][0]] = a[i][1];
14498+
var j = a[i][0];
14499+
if (c[j] != undefined)
14500+
return;
14501+
c[j] = a[i][1];
1449614502
}
14497-
} else {
14498-
c.$init0$ =
14499-
//(function(cs, a) {return
14500-
function(){
14501-
var cs = c.superclazz;
14502-
cs && cs.$init0$ && cs.$init0$.apply(this);
14503-
for (var i = a.length; --i >= 0;){
14504-
this[a[i][0]] = a[i][1];
14505-
}
14506-
};
14507-
// })(c.superclazz, a);
14503+
return;
1450814504
}
14505+
c.$init0$ = function(){
14506+
var cs = c.superclazz;
14507+
cs && cs.$init0$ && cs.$init0$.apply(this);
14508+
for (var i = a.length; --i >= 0;){
14509+
this[a[i][0]] = a[i][1];
14510+
}
14511+
};
1450914512

1451014513
}
1451114514

0 commit comments

Comments
 (0)