Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2654

Joint compilation Groovy class stubs missing exception information

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.4
    • 1.5.5, 1.6-beta-1
    • None
    • None
    • Groovy Version: 1.5.4 JVM: 1.4.2_13-b06

    Description

      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.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            rmisek Ryan Misek
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: