Type variable information is not always maintained for anonymous classes

Sergey merkel05 at gmail.com
Sat Dec 8 01:06:38 UTC 2018

Hi Vicente,

Thanks for your quick reply!

Let me briefly summarize what I've discovered and maybe
you'll give me some thoughts on how you think I should
approach the problem.

During the execution inside the lambda body, in order to be able
to fetch class' generic type parameters, lookup inside the
ClassScope [1] should happen. That lookup is done on the anonymous
class first, thus it is a "class scope". In both cases ClassScope is
and during the lookup [2] call is delegated to the enclosing scope.

In case of anonymous class being enclosed by a method (a main method in
the attached test case) lookup works perfectly fine - it just takes the
TypeVariable from within the method's scope.

In case of lambda that's a bit trickier as there's a synthetic method being
generated which in it's turn enclosed by the same class as the main
method in the attached test case. I'm not sure if that is intended
In that case the lookup is being delegated to the enclosing class, which
happen. Lookup in my opinion should happen within the lambda's enclosing

Amusing part is that if enclosing class has the same type variable name
will succeed:

public class Bug8213465<T extends CharSequence> {
    static abstract class A<R> {}
    public static <T extends Number> void main(String[] args) {
        Runnable r2 = () -> printIt(new A<T>(){}.getClass()); // that will

I think special treatment of synthetic methods is necessary here.
At least for the case above Type Variable lookup should be delegated to
the main method instead of the enclosing class.

So if you have any suggestions on how should I try to approach the problem,
please let me know. Any thoughts/suggestions/advise would be much



On Sat, 8 Dec 2018 at 01:12, Vicente Romero <vicente.romero at oracle.com>

> Hi Sergey,
> Thanks for your interest in the bug, yes if you feel like, please feel
> free to give it a try.
> Vicente
> On 12/7/18 6:53 PM, Sergey wrote:
> > Hi everyone,
> >
> > Recently I've stumbled upon this bug
> > https://bugs.openjdk.java.net/browse/JDK-8213465
> > which is named the same way as in the header of an email. I've done a
> > little bit of
> > investigation and keen to fix it. Though I'm afraid that most likely fix
> > wouldn't be just
> > a one-liner. Thus I want to ask for a little bit of a guidance and make
> > sure, that I do not cross
> > anyone else. With that being said, if ticket isn't in progress and no one
> > minds I want to make
> > an attempt on it.
> >
> > Thanks and regards,
> > Sergei

More information about the core-libs-dev mailing list