Project: JDT
Bug 297566 [clean up] StackOverflow in callsWrittingConstructor of VariableDeclarationFinder in VariableDeclarationFix on Save
Reported: 2009-12-11 04:10:27 | Status: resolved fixed

User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Build Identifier: Build id: 20090920-1017 When saving a Java File, I got the following StackOverflowError. java.lang.StackOverflowError at org.eclipse.jdt.internal.compiler.lookup.Binding.isValidBinding(Binding.java:92) at org.eclipse.jdt.core.dom.DefaultBindingResolver.getMethodBinding(DefaultBindingResolver.java:230) at org.eclipse.jdt.core.dom.MethodBinding.getMethodDeclaration(MethodBinding.java:423) at org.eclipse.jdt.core.dom.DefaultBindingResolver.findDeclaringNode(DefaultBindingResolver.java:170) at org.eclipse.jdt.core.dom.CompilationUnit.findDeclaringNode(CompilationUnit.java:332) at org.eclipse.jdt.internal.corext.dom.ASTNodes.findDeclaration(ASTNodes.java:239) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:293) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) at org.eclipse.jdt.internal.corext.fix.VariableDeclarationFix$VariableDeclarationFinder.callsWrittingConstructor(VariableDeclarationFix.java:297) ... Looking at the implementation it turns out that the MethodBinding tested against the HashSet doesn't override hashCode and equals. The condition used in the if-branch on line 290: if (writingConstructorBindings.contains(constructorBinding)) { will never be "true", if MethodBinding is not the same object. Reproducible: Didn't try

Files changed in fix:
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/VariableDeclarationFix.java