Summary: | [1.3][compiler] Severe runtime errors with anonymous classes | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Toby Ho <toby.ho> | ||||
Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||
Status: | VERIFIED FIXED | QA Contact: | |||||
Severity: | major | ||||||
Priority: | P3 | CC: | martinae | ||||
Version: | 3.1 | ||||||
Target Milestone: | 3.3 M5 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Toby Ho
2006-05-15 14:00:34 EDT
This is fixed in HEAD. I get: containing class: Bug@360be0 finalArgment: I am a final Argument. field: I am a field of the containing class. Actually, the problem is still there. The steps were incomplete I believe, it only occurs when -source 1.3 is specified. Toby - can you confirm this ? When using javac 1.3.1 or 1.4.2 with -source 1.3, I also reproduce the issue. Javac 1.5.0 -source 1.3 no longer reproduces. Exact Javac versions were: Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01a) Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-ea-b01) Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b02) Actually, this behavior is intended. Post 1.4 source level, synthetic initializations occur prior to explicit constructor call. In clear, the super constructor call from the anonymous default constructor is calling back into the anonymous before the field this$0 (representing Bug.this) got a chance to be initialized. The offending runtime path is: Bug$1()->TemplateClass()->TemplateClass.doIt()->Bug$1.doItPart(). Prior to source 1.4, the code of the anonymous constructor does: <init>(Bug this$0) { super(); this.this$0 = this$0; ... } post 1.4, VMs allow better support of synthetics, and allow: <init>(Bug this$0) { this.this$0 = this$0; super(); ... } Need to double check whether our configuration strategy is valid or not. It feels like from 1.5 on javac is producing code as if source level was >= 1.4 wrt to synthetic initializations. I believe the configuration behavior should be based on target level, rather than source level. When using javac with -source 1.3 -target 1.3, it issues the NPE as well. Actually, we already toggle behavior based on -target setting. So we are fine there. Now, we seem to have a mismatch on the batch compiler itself. When using -1.5 -source 1.3, javac leaves the target at 1.5 !? Toby: the proper solution is for you to specify explicitly using a -1.4 target or above in your compiler settings. javac 1.3 -source 1.3, sets the default target to 1.1 javac 1.4 -source 1.3, sets the default target to 1.2 javac 1.5 -source 1.3, sets the default target to 1.4 javac 1.6 -source 1.3, sets the default target to 1.4 We should revisit our defaults to match these. For current time being, Toby, please make these settings explicit. Olivier - pls check all source levels, and provide a patch to the batch compiler. ideally, you should paste here a matrix of defaults. Martin - there may need to be some alignments in UI. Likely something for 3.3 at best. (In reply to comment #2) > Actually, the problem is still there. The steps were incomplete I believe, it > only occurs when -source 1.3 is specified. > > Toby - can you confirm this ? > I have been using source level 1.4. (In reply to comment #9) > Olivier - pls check all source levels, and provide a patch to the batch > compiler. > ideally, you should paste here a matrix of defaults. List of defaults: javac 1.3: -source option doesn't exist. default target 1.1 javac 1.4: -source 1.2, default target 1.2 -source 1.3, default target 1.2 -source 1.4, default target 1.4 javac 1.5: -source 1.2, default target 1.4 -source 1.3, default target 1.4 -source 1.4, default target 1.4 -source 1.5, default target 1.5 javac 1.6: -source 1.2, default target 1.4 -source 1.3, default target 1.4 -source 1.4, default target 1.4 -source 1.5, default target 1.6 -source 1.6, default target 1.6 javac 1.7: -source 1.2, default target 1.4 -source 1.3, default target 1.4 -source 1.4, default target 1.4 -source 1.5, default target 1.6 -source 1.6, default target 1.6 -source 1.7, default target 1.7 Created attachment 57618 [details]
Proposed fix
(In reply to comment #10) > I have been using source level 1.4. You must have the target set to 1.1 and this would explain the error. I adjusted the compiler's defaults. I'll released once all the tests are done. (In reply to comment #9) > Martin - there may need to be some alignments in UI. Martin, The UI doesn't allow the source to be 1.2. This is allowed by the compiler and javac. Might not be a big deal since source 1.2 doesn't add any value. Released for 3.3M5. Added regression tests org.eclipse.jdt.core.tests.compiler.regression.BatchCompilerTest#test107/121 (In reply to comment #14) > The UI doesn't allow the source to be 1.2. This is allowed by the compiler and > javac. Might not be a big deal since source 1.2 doesn't add any value. Our batch compiler doesn't allow 1.2 as well for the source value. So this is not something we should change. Verified for 3.3 M5 using build I20070205-0009 please file a bug against jdt.ui if I need to change something. As long as you respect the defaults, you are fine. I haven't check them on the UI side. |