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

More laziness to prevent Stackoverflow exceptions. #2260

Merged
merged 8 commits into from
May 9, 2022

Conversation

CRogers
Copy link
Contributor

@CRogers CRogers commented May 9, 2022

Before this PR

When testing this out on a real project using a jdk provider that did a configuration resolutions, Gradle checks (for some reason) checks whether JavaCompile are using toolchains:

https://github.com/gradle/gradle/blob/v7.4.2/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaBasePlugin.java#L290

This then causes a loop:

* What went wrong:
Could not determine the dependencies of task ':compileJava'.
> Failed to query the value of extension 'errorprone' property 'enabled'.
   > Failed to calculate the value of extension 'javaVersions' property 'jdks'.
      > Could not resolve all dependencies for configuration ':dockerBaseImages'.
         > Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
            > Failed to calculate the value of extension 'javaVersions' property 'jdks'.
               > Could not resolve all dependencies for configuration ':dockerBaseImages'.
                  > Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
                     > Failed to calculate the value of extension 'javaVersions' property 'jdks'.
                        > Could not resolve all dependencies for configuration ':dockerBaseImages'.
                           > Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
        // continues forever
        at com.palantir.gradle.jdks.JdksPlugin.lambda$apply$1(JdksPlugin.java:55)
        // snip
        at org.gradle.api.plugins.JavaBasePlugin.lambda$determineCompatibility$7(JavaBasePlugin.java:290)
        at org.gradle.util.internal.GUtil.uncheckedCall(GUtil.java:458)
        at org.gradle.internal.extensibility.ConventionAwareHelper$2.doGetValue(ConventionAwareHelper.java:96)
        at org.gradle.internal.extensibility.ConventionAwareHelper$MappedPropertyImpl.getValue(ConventionAwareHelper.java:147)
        at org.gradle.internal.extensibility.ConventionAwareHelper.getConventionValue(ConventionAwareHelper.java:129)
        at org.gradle.api.tasks.compile.JavaCompile_Decorated.getTargetCompatibility(Unknown Source)
        at org.gradle.api.plugins.jvm.internal.DefaultJvmPluginServices.lambda$configureDefaultTargetPlatform$5(DefaultJvmPluginServices.java:228)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.preventFromFurtherMutation(DefaultConfiguration.java:1092)
        // snip        com.palantir.dockerbaseimages.gradle.resolver.BaseImageResolver.resolveDockerBaseImagesDistThrowing(BaseImageResolver.java:99)
        at com.palantir.gradle.javadist.RootSlsDockerPlugin.lambda$apply$4(RootSlsDockerPlugin.java:35)
        // snip
        at com.palantir.gradle.jdks.DelayedConfigurableMap.lambda$get$3(DelayedConfigurableMap.java:69)
        at com.palantir.gradle.jdks.DelayedConfigurableMap.get(DelayedConfigurableMap.java:68)
        // snip
        at com.palantir.gradle.jdks.JdksPlugin.lambda$apply$1(JdksPlugin.java:55)
        // snip
        at org.gradle.api.plugins.JavaBasePlugin.lambda$determineCompatibility$7(JavaBasePlugin.java:290)

After this PR

==COMMIT_MSG==
Make interactions with gradle java toolchains more lazy, so StackOverflowErrors do not occur
==COMMIT_MSG==

Possible downsides?

@CRogers CRogers requested a review from carterkozak May 9, 2022 13:20
@changelog-app
Copy link

changelog-app bot commented May 9, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Make interactions with gradle java toolchains more lazy, so StackOverflowErrors do not occur

Check the box to generate changelog(s)

  • Generate changelog entry

@carterkozak
Copy link
Contributor

Hmm

Caused by: java.lang.ClassCastException: class com.palantir.baseline.plugins.javaversions.BaselineJavadocTool cannot be cast to class org.gradle.api.tasks.javadoc.internal.JavadocToolAdapter

import org.gradle.process.internal.ExecActionFactory;
// CHECKSTYLE:ON

final class BaselineJavadocToolAdapter extends JavadocToolAdapter {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carterkozak Very, very unfortunately Gradle casts the public interface for JavadocTool to the internal JavadocToolAdapter:

https://github.com/gradle/gradle/blob/v7.4.2/subprojects/language-java/src/main/java/org/gradle/api/tasks/javadoc/Javadoc.java#L207

So I've had to extend that class (thankfully none of it is final) and managed to inject what it needs to work. It feels brittle doing this but we don't have a choice. The only possibly redeeming factor is this seems to not have changed in 2 years since it was created.

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Least gross option, heh

@bulldozer-bot bulldozer-bot bot merged commit 7346e88 into develop May 9, 2022
@bulldozer-bot bulldozer-bot bot deleted the callumr/more-lazy branch May 9, 2022 16:01
@svc-autorelease
Copy link
Collaborator

Released 4.130.0

bulldozer-bot bot pushed a commit to palantir/witchcraft-api that referenced this pull request May 9, 2022
###### _excavator_ is a bot for automating changes across repositories.

Changes produced by the roomba/latest-baseline-oss check.

# Release Notes
## 4.130.0
| Type | Description | Link |
| ---- | ----------- | ---- |
| Fix | Make interactions with gradle java toolchains more lazy, so `StackOverflowError`s do not occur | palantir/gradle-baseline#2260 |



To enable or disable this check, please contact the maintainers of Excavator.
This was referenced May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants