Issue Details (XML | Word | Printable)

Key: GROOVY-2654
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Ryan Misek
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Joint compilation Groovy class stubs missing exception information

Created: 03/Mar/08 10:01 AM   Updated: 17/Apr/08 07:26 AM   Resolved: 10/Apr/08 03:24 AM
Component/s: None
Affects Version/s: 1.5.4
Fix Version/s: 1.5.5, 1.6-beta-1

Time Tracking:
Not Specified

Environment: Groovy Version: 1.5.4 JVM: 1.4.2_13-b06


 Description  « Hide

Java stubs created from Groovy classes do not contain the "throws SomeException" in the method signature. See the following to recreate the problem:

Foo.java
package com.foo;
import java.sql.SQLException;
public class Foo {
	public static void main(String [] args) {
		try {
			FooHelper.doSomeSQLStuff();
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
FooHelper.groovy
package com.foo
class FooHelper {
	static doSomeSQLStuff() throws java.sql.SQLException {
		throw new java.sql.SQLException()
	}
}
build.xml
<?xml version="1.0"?>
<project name="foo" default="runGroovyC" basedir=".">
	<property name="dir.bin" value="bin" />
	<property name="dir.lib" value="lib" />
	<property name="dir.src" value="src" />
	<property name="dir.build" value="build" />

	<path id="project.classpath">
		<pathelement location="${dir.build}" />
		<fileset dir="${dir.lib}" includes="**/*.jar" />
	</path>

	<target name="clean" description="Remove all generated files.">
		<delete dir="${dir.build}" />
	</target>

	<target name="prepare" description="Create directories for build and distribution">
		<mkdir dir="${dir.build}" />
	</target>

	<taskdef name="groovyc" classpathref="project.classpath" classname="org.codehaus.groovy.ant.Groovyc" />
	<taskdef name="groovy" classpathref="project.classpath" classname="org.codehaus.groovy.ant.Groovy" />

	<target name="runGroovyC" depends="clean, prepare">
		<groovyc srcdir="${dir.src}" destdir="${dir.build}" listfiles="yes" verbose="yes">
		  <classpath>
		    <path refid="project.classpath"/>
		  </classpath>
		  <javac source="1.4" target="1.4" listfiles="yes" />
		</groovyc>
	</target>
</project>

Here's the generated stub for FooHelper.groovy (FooHelper.java) (I had to be quick to grab this one before it was cleaned up)

FooHelper.java
package com.foo;

import groovy.util.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import groovy.lang.*;
import java.net.*;

public class FooHelper
  extends java.lang.Object  implements
    groovy.lang.GroovyObject {
groovy.lang.MetaClass metaClass;
public FooHelper() {}
public static java.lang.Object doSomeSQLStuff() { return null;}
public groovy.lang.MetaClass getMetaClass() { return (groovy.lang.MetaClass)null;}
public java.lang.Object invokeMethod(java.lang.String method, java.lang.Object arguments) { return null;}
public java.lang.Object getProperty(java.lang.String property) { return null;}
public void setProperty(java.lang.String property, java.lang.Object value) { }
public void setMetaClass(groovy.lang.MetaClass value) { }
}

When executing the above example, you should get a "exception java.sql.SQLException is never thrown in body of corresponding try statement" error.



Jochen Theodorou added a comment - 28/Mar/08 09:19 AM

I add a fix for this in 1.6, 1.5.5 follows soon


Paul King added a comment - 10/Apr/08 03:24 AM

I merged Jochen's patch into 1.5.5 branch and it seems to do everything as advertised. It might be nice to have a keepStubs="true" flag on groovyc to assist with debugging.