Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding stack overflow when decoding generic types #170

Closed
wants to merge 3 commits into from

Conversation

will-lauer
Copy link

Fixes #148.

  • Copies GenericsVisitor from Groovy
  • In checkGenericsUsage, ensure wildcards don't cause generic resolution to fail
  • In checkGenericsUsage, don't get caught in an infinite loop while printing generic type names

@pivotal-issuemaster
Copy link

@will-lauer Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@will-lauer Thank you for signing the Contributor License Agreement!

@will-lauer
Copy link
Author

I've signed the CLA, but I just wanted to note the origin of this change. I've copied the file GenericsVisitor.java from the main goovy distribution from Apache and updated it to fix this particular issue, so the file does still retain the Apache copyright.

@eric-milles
Copy link
Member

The file would retain the original copyright. Have you wrapped your change in "// GRECLIPSE add" and "// GRECLIPSE end"? Did you patch each of the Groovy versions that this affects? Is there a test case that can reproduce the issue?

@will-lauer
Copy link
Author

I missed adding the GRECLIPSE markers. I've just pushed another commit to include those. I've only addressed Groovy 2.4, as that is the only version I use and is where I originally found the problem. I don't know if problem occurs with other versions of groovy as well.

I haven't figured out how to implement a unit test for this, but this is a simple example that triggers the problem in the associated git issue (#148). If anyone can point me in the right direction for implementing this unit test, I can take a crack at it.

@eric-milles
Copy link
Member

Yes indeed, Issue #148 example still fails as described. Add this to GenericsTests in the core.tests.compiler project.

    void testIssue148() {
        String[] sources = [
            'A.java', '''
            public interface A<Q extends A<? super Q>> {
            }''',

            'B.groovy', '''
            class B {
              public void test(A<?> a) {
              }
            }'''
        ]

        runConformTest(sources)
    }

@eric-milles
Copy link
Member

eric-milles commented Nov 2, 2016

It appears from the test that the essential change is only this one:

            // GRECLIPSE edit
            //if (!nType.isDerivedFrom(cnType)) {
            if (!nTypes[i].isWildcard() && !nType.isDerivedFrom(cnType)) {
            // GRECLIPSE end

Or should there be an error generated for this case and the stack overflow is getting in the way of that?

@will-lauer
Copy link
Author

Its been a while since I looked at this, so its only coming back to me slowly. I think the problem listed in #148 was only one of two related issues. I guess I'll need to dig up an example of the other. But what was happening was an infinite look trying to resolve the type name. I'll see if I can put together an example of that as well.

@eric-milles
Copy link
Member

So if I compile both as Java, all is well. So no warning for the Groovy case. When I compile with groovyc, all is well. So it does seem a Greclipse patch is the right route.

Possible fix for groovy#148.
- Ensure wildcards don't cause generic resolution to fail
- don't get caught in an infinite loop while printing generic type names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants