Community
Participate
Working Groups
Overview: The following incorrect code causes the compiler to fail and will prevent the class from being opened in the java editor. Steps to reproduce: Create a java class called BreakEclipse in the default package Copy paste following code /* Begin test file */ import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class BreakEclipse { JButton myButton = new JButton(); JTree myTree = new JTree(); ActionListener action; BreakEclipse() { action = new ActionListener() { public void actionPerformed(ActionEvent e) { if (true) { // unlock document final Object document = new Object(); myButton.addActionListener(new ActionListener() { private static boolean selectionChanged; static TreeSelectionListener list = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { selectionChanged = true; } }; static { myTree.addTreeSelectionListener(list); } public void actionPerformed(ActionEvent e) { if(!selectionChanged) myButton.removeActionListener(this); } }); } } }; } public static void main(String[] args) { new BreakEclipse(); } } /* End test file */ Actual Results: When a save is attempted an error: Save Failed:org.eclipse.jdt.internal.compiler.ast.TrueLiteral Similar code in our application caused an error: Save Failed:org.eclipse.jdt.internal.compiler.ast.MessageSend When I restarted eclipse after getting the second error the open type did not function, the Package explorer didn't function and the file could not be opened. Will attach eclipse logs Tested in eclipse 3.1 final and 3.1.1 (Build id: M20050929-0840) final releases. Did not test in a 3.2 release. Expected Results: Should show a compile error in the java editor
Created attachment 27915 [details] Most recent log file
Created attachment 27916 [details] second log file
Created attachment 27917 [details] First log file
I will investigate.
The constructor is misparsed, something like: BreakEclipse() { super(); new ActionListener() { public void actionPerformed(ActionEvent e) { if (new ActionListener() { private static boolean selectionChanged; static TreeSelectionListener list = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { selectionChanged = true; } }; static { myTree.addTreeSelectionListener(list); } public void actionPerformed(ActionEvent e) { if ((!selectionChanged)) myButton.removeActionListener(this); } }) { final Object document = new Object(); myButton.addActionListener(); } } } = true; }
Once addressed, pls backport fix to 3.1 maintenance branch.
My guess for now is that we miss the consumption of the true literal on the way in the SourceElementParser.
I am testing a fix. The presence of the static initializer was the cause of the failure. Now the compiler properly reports wrong usage of static initializer inside an anonymous class.
Created attachment 27951 [details] Proposed fix
+1 for 3.1.2
Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.compiler.regression.AssignmentTest.test038.
Backported to 3.1 maintenance stream. Same regression test.
Verified for 3.1.2 using build M20060109-1200.
Verified for 3.1.2 using build M20060109-1200 (maxime)
Verified for 3.2 M4 using build I20051215-1506.