Skip to content

Commit 5173cb2

Browse files
author
zhourenjian
committed
Fixed bug#1844474 Endless recursion on Collection.toString()
== in java means SAME INSTANCE, while == in javascript means "try to do something, convert the two operands, and see if they match". So, java == shouldn't always be converted to javascript === Thanks, Simone Gianni
1 parent d1d8191 commit 5173cb2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.eclipse.jdt.core.dom.SimpleType;
4848
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
4949
import org.eclipse.jdt.core.dom.Statement;
50+
import org.eclipse.jdt.core.dom.StringLiteral;
5051
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
5152
import org.eclipse.jdt.core.dom.SuperFieldAccess;
5253
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
@@ -1065,6 +1066,15 @@ public boolean visit(InfixExpression node) {
10651066
charVisit(node.getLeftOperand(), beCare);
10661067
buffer.append(' ');
10671068
buffer.append(operator);
1069+
if ("==".equals(operator) || "!=".equals(operator)) {
1070+
if (typeBinding != null && !typeBinding.isPrimitive()
1071+
&& !(node.getLeftOperand() instanceof NullLiteral)
1072+
&& !(node.getRightOperand() instanceof NullLiteral)
1073+
/*&& !(node.getLeftOperand() instanceof StringLiteral) // "abc" == ...
1074+
&& !(node.getRightOperand() instanceof StringLiteral)*/) {
1075+
buffer.append('=');
1076+
}
1077+
}
10681078
buffer.append(' ');
10691079
charVisit(node.getRightOperand(), beCare);
10701080
List extendedOperands = node.extendedOperands();

0 commit comments

Comments
 (0)