Skip to content

Commit d18c927

Browse files
committed
// BH 6/23/2018 -- synchronized(a = new Object()) {...}
---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
1 parent 2b68895 commit d18c927

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed
40 Bytes
Binary file not shown.
40 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
125126
// BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
126127
// BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var
127128
// BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
@@ -909,7 +910,11 @@ public boolean visit(SwitchCase node) {
909910
}
910911

911912
public boolean visit(SynchronizedStatement node) {
912-
// not implemented in JS, as there is only one thread
913+
// we wrap this with a simple if() statement,
914+
// checking that it is not null
915+
buffer.append("if(!(");
916+
node.getExpression().accept(this);
917+
buffer.append("){throw new NullPointerException()}else");
913918
node.getBody().accept(this);
914919
return false;
915920
}

0 commit comments

Comments
 (0)