Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 354609

Summary: EGL code has try-block on AnyException but generated Java has unhandled exception
Product: z_Archived Reporter: Kathy Carroll <carrollk>
Component: EDTAssignee: Project Inbox <edt.javagen-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jeffdouglas, mheitz
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Kathy Carroll CLA 2011-08-12 08:22:31 EDT
Generated Java is getting the error message:
             Unhandled exception type IOException

EGL code:

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

ExternalType File type JavaObject {packageName = "java.io"}
	 constructor (pathname String In);
	 function getAbsolutePath() returns (String);
	 function createNewFile() returns (boolean);
	 function mkdirs() returns (boolean);
	 function exists() returns (boolean);
end

ExternalType FileWriter type JavaObject { packageName = "java.io"}
	constructor (file File In);
	constructor (filename String In);
	function write(str String In);
//	function close_() {javaName ="close"};  //354044 The javaName annotation for external JavaObject functions is missing 
end

ExternalType IOException type JavaObject { packageName = "java.io"}
end
================
handler CreateResultFile 
	function createFile(fileDirectory String in, fullFileName String in, fileContent String in)
		myfile File  = new File(fileDirectory);
		//if(!etrFile.exists())
			createdDirs boolean = myfile.mkdirs();
			if(createdDirs)
				sysLib.writeStdOut("directories created");			
			end					
		//end
		
		outWriter FileWriter;  
		try
			syslib.writeStdOut (myfile.getAbsolutePath());
			
			outWriter = new FileWriter(fullFileName);
			outWriter.write(fileContent);
//			outWriter.close_();
//		onException (ioExp IOException)
//			syslib.writeStdOut("IOException occrred!");
		onException (exp AnyException)
			syslib.writeStdOut("oops can't get to it");
			syslib.writeStdOut("Exception occurred!");
		end
	end	
end

Generated JAVA

		FileWriter outWriter = null;
		try {
			SysLib.writeStdout(myfile.getAbsolutePath());
			outWriter = new FileWriter(fullFileName);
			outWriter.write(fileContent);
		}
		catch (AnyException exp) {
			String eze$Temp3 = Constants.EMPTY_STRING;
			eze$Temp3 = "oops can't get to it";
			SysLib.writeStdout(eze$Temp3);
			String eze$Temp4 = Constants.EMPTY_STRING;
			eze$Temp4 = "Exception occurred!";
			SysLib.writeStdout(eze$Temp4);
		}

No java compile error in RBD for this example
Comment 1 Jeff Douglas CLA 2011-08-12 15:03:00 EDT
The root of this problem is that IOException has not yet been defined in EGL.

This needs to be added to the EGL source files that are generated into the IR logic.
Comment 2 Matt Heitz CLA 2011-08-12 15:15:58 EDT
Actually, the problem is that an onException block catching AnyException needs to be generated differently than other onException blocks.  I'm familiar with this because RBD had to deal with this problem too.

We have to generate a catch for all Exceptions.  If we catch something that's not one of our exceptions, create an AnyException to represent it.

EGL
---
onException (exp AnyException)
  // ...body of the onException block...
end


Generated Java
--------------
catch ( Exception ezeTemp1 )
{
  exp AnyException;
  if ( ezeTemp1 instanceof AnyException )
    exp = (AnyException)ezeTemp1;
  else
    exp = ...some code to make an AnyException from ezeTemp1...

  // ...code for the body of the onException block...
}
Comment 3 Matt Heitz CLA 2011-08-14 11:35:02 EDT
I made the changes in TryStatementTemplate.
Comment 4 Kathy Carroll CLA 2011-08-15 14:33:38 EDT
verified
Comment 5 Lisa Lasher CLA 2011-10-11 16:22:47 EDT
Closing this defect.