6723444: javac fails to substitute type variables into a constructor's throws clause
Maurizio Cimadamore
Maurizio.Cimadamore at Sun.COM
Wed Jul 23 06:35:39 PDT 2008
Hi Mark
thanks for your mail,
I looked at this bug only yesterday and I think I came up with a fix.
However, I'm not 100% sure of the change (though all regression tests
execute without problems) and I like to see your patch; perhaps your
approach is way smarter than mine :-) !
The main issue here is that a JCNewClass node of the AST keeps only
track of the constructor symbol (which means that we have only access to
the 'formal' constructor, "<X extends Throwable> Hello(Foo<X> foo)
throws X" in this case). Since the actual type of the constructor (the
one with Exception in place of X) get lost during attribution, there's
no way to recover that info at a later point during flow analysis.
My fix basically consists in storing the actual type of the constructor
method inside the 'type' field of the constructor field stored inside
the AST node.
Regards
Maurizio
Mark Mahieu wrote:
> Hi,
>
> Is anyone already working on this bug? I see the bug entry now has an
> evaluation.
>
> If not, I believe I have a fix for it, as well as for a related issue
> which occurs when the class being instantiated is an anonymous class
> (flow analysis of the class def also encounters unsubstituted type
> variables) - note the two errors reported in this derivative of the
> bug's example:
>
>
> public class Hello {
> static class Foo<X> {}
>
> <X extends Throwable> Hello(Foo<X> foo) throws X {}
>
> public static void main(String[] args) throws Exception {
> new Hello(new Foo<Exception>()) {};
> }
> }
>
>
> Hello.java:7: unreported exception X in default constructor
> new Hello(new Foo<Exception>()) {};
> ^
> Hello.java:7: unreported exception X; must be caught or declared to be
> thrown
> new Hello(new Foo<Exception>()) {};
> ^
> 2 errors
>
>
> I should be able to submit a patch and jtreg test case in the next day
> or so if it's of interest.
>
>
> Best regards,
>
> Mark
More information about the compiler-dev
mailing list