Bug 19916 - Error accessing value from uninitialized localvariable
Summary: Error accessing value from uninitialized localvariable
Status: RESOLVED DUPLICATE of bug 16279
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 F3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-11 12:00 EDT by Judy Mullins CLA
Modified: 2002-08-21 10:46 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Judy Mullins CLA 2002-06-11 12:00:30 EDT
We have found a potential class loading issue? However, it seems to have been 
resolved in Eclipse 2.0 (F2 driver). However, we are looking for a workaround 
in the current workbench (Eclipse 1.0). This doesn't seem to be a problem with 
the workbench's JRE since we have built the source and run it successfully with 
the same JRE outside the workbench. Is this a known problem? Can you provide a 
workaround for 1.0? 

Steps to reproduce:
======================= 

package problem2;
public class ClassLoadTest {
	public static void main(String[] args) {
		try {
			Class clz1 = Class.forName("problem2.C");
			System.out.println("success");
		} catch (Exception e) {
			System.out.println("error");
			e.printStackTrace();
		}
	}
}

======================= 

package problem2;
public class C {

	boolean b = false;

	private Integer f() {
		while (true) {
			try {
				int x = 3;
				synchronized (this) {
					return null;
				}
			} finally {
				if (b)
					synchronized (this) {
					int y = 3;
				}
			}
		}
	}
}

======================= 

Running this in Workbench will give you the following error: 

java.lang.VerifyError: (class: problem2/C, method: f signature: ()
Ljava/lang/Integer;) Accessing value from uninitialized localvariable 3 
at java.lang.Class.forName1(Native Method) 
at java.lang.Class.forName(Class.java:134) 
at problem2.ClassLoadTest.main(ClassLoadTest.java:7) 
Exception in thread "main"
Comment 1 Olivier Thomann CLA 2002-06-11 13:49:30 EDT
The following code would work fine:
	private Integer f() {
		int x;
		int y;
		while (true) {
			try {
				x = 3;
				synchronized (this) {
					return null;
				}
			} finally {
				if (b) {
					synchronized (this) {
						y = 3;
					}
				}
			}
		}
	}

The problem comes from locals defined in a try/finally when the try block 
returns. If you extract your locals before the try statement, it will work fine.
Comment 2 Olivier Thomann CLA 2002-06-11 16:01:40 EDT
Is this good enough for a workaround?
Comment 3 Judy Mullins CLA 2002-06-11 16:16:38 EDT
I sent the workaround to the customer.  I haven't heard anything back yet, but 
I'll let you know as soon as I do.
Comment 4 Philipe Mulet CLA 2002-06-12 05:04:11 EDT
This bug is a duplicate of bug 16279, which got addressed in 2.0 stream. 
Backporting would be fairly dangerous, since the change in 2.0 stream is quite 
nasty and relying on other changes.
Comment 5 Philipe Mulet CLA 2002-06-12 05:42:02 EDT

*** This bug has been marked as a duplicate of 16279 ***
Comment 6 Judy Mullins CLA 2002-06-12 10:07:16 EDT
From the customer:

Thank you for the workaround, actually we had discovered this as a workaround 
ourselves as well. However, is their a better workaround, since enclosing 
variables within a try block achieves data hiding and provides us with better 
scoping. Furthermore, it is acceptable code since running the code as is with 
virtually any JRE outside the workbench will work. Do you know of any other 
workarounds that we may be able to try? 
Comment 7 Judy Mullins CLA 2002-06-26 16:49:41 EDT
From the customer:

What I need to know is, 
Which compiler..? the JDK given by Hursley..? The javac..? 
I understand that the development of a fix can be tricky, sensitive and 
dangerous in some situation maybe this situation might be one but I need to 
explain to the customer why..? as he is demading a fix, because the workaround 
is not a good workaround as he has hundread and hundreads of classes to modify 
to apply the workaround that was suggested (ie. go into every class of his app 
and take the Fields out of the try{} catch block) 

Reply:

The problem is in the internal compiler that is included in Eclipse, WSWB and 
WSAD, not an external compiler like Javac. Bad bytecodes are being generated 
and therefore the class cannot be loaded. 

The compiler is started from: 
org.eclipse.pde.internal.core.JDTCompilerAdapter 
and it's in the org.eclipse.jdt.core plugin. 

Source is in wswb10\eclipse\plugins\org.eclipse.jdt.core\jdtcoresrc.zip, mostly 
in the parser and compiler packages. 

The reason that development says that backporting would be dangerous is that so 
much code has been changed that relies upon previous changes. Other 
functionality could be easily broken.
Comment 8 Philipe Mulet CLA 2002-08-20 18:52:50 EDT
Backporting fix to 1.0 (release into v_146). The fix is quite big, will ensure 
we pass jck1.3a before calling it good.
Comment 9 Judy Mullins CLA 2002-08-21 10:46:50 EDT
Support Note: HD100126.