Bug 88841 - IAE while opening ASTView
Summary: IAE while opening ASTView
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-23 08:16 EST by Frederic Fusier CLA
Modified: 2005-03-30 23:37 EST (History)
1 user (show)

See Also:


Attachments
This patch to fixes the problem... (2.10 KB, patch)
2005-03-23 08:19 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2005-03-23 08:16:32 EST
Using HEAD.

I got an IllegalArgumentException while trying to open ASTView on following example:
public class X {
    int
\ud800\udc05\ud800\udc04\ud800\udc03\ud800\udc02\ud800\udc01\ud800\udc00;
    void foo() {
        int
\ud800\udc05\ud800\udc04\ud800\udc03\ud800\udc02\ud800\udc01\ud800\udc00;
    }
}
Comment 1 Frederic Fusier CLA 2005-03-23 08:19:07 EST
Olivier, it seems that it comes from the fact that instanciated AST always
creates a Scanner with source level at ClassFileConstants.JDK1_3 even for JLS3...
Comment 2 Frederic Fusier CLA 2005-03-23 08:19:49 EST
Created attachment 19108 [details]
This patch to fixes the problem...

...But i don't know if this is the right thing to do.
Comment 3 Olivier Thomann CLA 2005-03-23 12:00:13 EST
I would not change the source level, but I would set the compliance level to be 1.5.
Comment 4 Olivier Thomann CLA 2005-03-23 12:09:05 EST
This patch:
Index: AST.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/AST.java,v
retrieving revision 1.138
diff -u -r1.138 AST.java
--- AST.java	15 Mar 2005 04:30:05 -0000	1.138
+++ AST.java	23 Mar 2005 17:06:32 -0000
@@ -196,17 +196,23 @@
      * @since 3.0
 	 */
 	private AST(int level) {
-		if ((level != AST.JLS2)
-			&& (level != AST.JLS3)) {
-			throw new IllegalArgumentException();
+		long complianceLevel = ClassFileConstants.JDK1_3;
+		switch (level) {
+			case AST.JLS3:
+				complianceLevel = ClassFileConstants.JDK1_5;
+			case AST.JLS2:
+				this.apiLevel = level;
+				break;
+			default:
+				throw new IllegalArgumentException();
 		}
-		this.apiLevel = level;
 		// initialize a scanner
 		this.scanner = new Scanner(
 				true /*comment*/, 
 				true /*whitespace*/, 
 				false /*nls*/, 
 				ClassFileConstants.JDK1_3 /*sourceLevel*/, 
+				complianceLevel /*complianceLevel*/, 
 				null/*taskTag*/, 
 				null/*taskPriorities*/,
 				true/*taskCaseSensitive*/);
@@ -296,12 +302,20 @@
 		} else if (JavaCore.VERSION_1_5.equals(sourceLevelOption)) {
 			sourceLevel = ClassFileConstants.JDK1_5;
 		}
+		Object complianceLevelOption = options.get(JavaCore.COMPILER_COMPLIANCE);
+		long complianceLevel = ClassFileConstants.JDK1_3;
+		if (JavaCore.VERSION_1_4.equals(complianceLevelOption)) {
+			complianceLevel = ClassFileConstants.JDK1_4;
+		} else if (JavaCore.VERSION_1_5.equals(complianceLevelOption)) {
+			complianceLevel = ClassFileConstants.JDK1_5;
+		}
 		// override scanner if 1.4 or 1.5 asked for
 		this.scanner = new Scanner(
 			true /*comment*/, 
 			true /*whitespace*/, 
 			false /*nls*/, 
 			sourceLevel /*sourceLevel*/,
+			complianceLevel /*complianceLevel*/,
 			null/*taskTag*/, 
 			null/*taskPriorities*/,
 			true/*taskCaseSensitive*/);

is passing your test case without failing ASTTest.

Let me know if this looks good for you.
Comment 5 Frederic Fusier CLA 2005-03-23 12:52:37 EST
Fine with me
Comment 6 Olivier Thomann CLA 2005-03-23 14:24:57 EST
Jim, do you believe that we should treat JLS2 and JLS3 differently regarding to
the decoding of Unicode 4 identifiers?
I could set the compliance level to be 1.5 in all cases. This would enable the
Unicode 4 support indenpendly from the source level.
So "assert" or "enum" would still be considered as valid identifiers and
identifiers written using Unicode 4 would also be valid identifiers.
Comment 7 Jim des Rivieres CLA 2005-03-23 14:54:47 EST
+1 - Handle JLS2 and JLS3 the same way regarding to the decoding of Unicode 4 
identifiers (using 1.5 rules) and classification of keywords (using 1.3 rules).
Comment 8 Olivier Thomann CLA 2005-03-23 16:32:03 EST
Fixed and released in HEAD.
Added regression test ASTConverter15Test.test0153.
Comment 9 Olivier Thomann CLA 2005-03-30 23:37:53 EST
Verified in 20050330-0500