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

Properly handle missing classes in metadata + precalculated requirements #10936

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

dstepanov
Copy link
Contributor

Fixes #10931

@dstepanov dstepanov added the type: improvement A minor improvement to an existing feature label Jul 2, 2024
@dstepanov
Copy link
Contributor Author

Newly generated code:

static {
        $ANNOTATION_METADATA = new AnnotationMetadataHierarchy(new AnnotationMetadata[]{new DefaultAnnotationMetadata(Map.of("io.micronaut.context.annotation.Factory", Map.of(), "jakarta.inject.Singleton", Map.of()), Map.of("io.micronaut.context.annotation.DefaultScope", Map.of("value", $micronaut_load_class_value_0())), Map.of("io.micronaut.context.annotation.DefaultScope", Map.of("value", $micronaut_load_class_value_0())), Map.of("io.micronaut.context.annotation.Factory", Map.of(), "jakarta.inject.Singleton", Map.of()), Map.of("io.micronaut.context.annotation.DefaultScope", List.of("io.micronaut.context.annotation.Factory")), false, false), new DefaultAnnotationMetadata(Map.of("io.micronaut.context.annotation.Bean", Map.of(), "io.micronaut.context.annotation.Requirements", Map.of("value", new AnnotationValue[]{new AnnotationValue("io.micronaut.context.annotation.Requires", Map.of("beans", new AnnotationClassValue[]{$micronaut_load_class_value_1()}, "missingBeans", new AnnotationClassValue[]{$micronaut_load_class_value_2()}), AnnotationMetadataSupport.ANNOTATION_DEFAULT_VALUES_PROVIDER)})), Map.of(), Map.of(), Map.of("io.micronaut.context.annotation.Bean", Map.of(), "io.micronaut.context.annotation.Requirements", Map.of("value", new AnnotationValue[]{new AnnotationValue("io.micronaut.context.annotation.Requires", Map.of("beans", new AnnotationClassValue[]{$micronaut_load_class_value_1()}, "missingBeans", new AnnotationClassValue[]{$micronaut_load_class_value_2()}), AnnotationMetadataSupport.ANNOTATION_DEFAULT_VALUES_PROVIDER)})), Map.of(), false, false)});

        try {
            $CONSTRUCTOR = new AbstractInitializableBeanDefinition.MethodReference(AFactory.class, "a", new Argument[]{Argument.of(X.class, "x")}, new DefaultAnnotationMetadata(Map.of("io.micronaut.context.annotation.Bean", Map.of(), "io.micronaut.context.annotation.Factory", Map.of(), "io.micronaut.context.annotation.Requirements", Map.of("value", new AnnotationValue[]{new AnnotationValue("io.micronaut.context.annotation.Requires", Map.of("beans", new AnnotationClassValue[]{$micronaut_load_class_value_1()}, "missingBeans", new AnnotationClassValue[]{$micronaut_load_class_value_2()}), AnnotationMetadataSupport.ANNOTATION_DEFAULT_VALUES_PROVIDER)}), "jakarta.inject.Singleton", Map.of()), Map.of("io.micronaut.context.annotation.DefaultScope", Map.of("value", $micronaut_load_class_value_0())), Map.of("io.micronaut.context.annotation.DefaultScope", Map.of("value", $micronaut_load_class_value_0())), Map.of("io.micronaut.context.annotation.Bean", Map.of(), "io.micronaut.context.annotation.Factory", Map.of(), "io.micronaut.context.annotation.Requirements", Map.of("value", new AnnotationValue[]{new AnnotationValue("io.micronaut.context.annotation.Requires", Map.of("beans", new AnnotationClassValue[]{$micronaut_load_class_value_1()}, "missingBeans", new AnnotationClassValue[]{$micronaut_load_class_value_2()}), AnnotationMetadataSupport.ANNOTATION_DEFAULT_VALUES_PROVIDER)}), "jakarta.inject.Singleton", Map.of()), Map.of("io.micronaut.context.annotation.DefaultScope", List.of("io.micronaut.context.annotation.Factory")), false, false));
        } catch (Throwable var0) {
            $FAILURE = var0;
            $CONSTRUCTOR = null;
        }

        $INFO = new AbstractInitializableBeanDefinition.PrecalculatedInfo(Optional.empty(), false, false, false, false, false, false, false, false);
        $PRE_CONDITIONS = new Condition[]{new MatchesPresenceOfClassesCondition(new AnnotationClassValue[]{$micronaut_load_class_value_1()})};
        $POST_CONDITIONS = new Condition[]{new MatchesPresenceOfBeansCondition(new AnnotationClassValue[]{$micronaut_load_class_value_1()}), new MatchesAbsenseOfBeansCondition(new AnnotationClassValue[]{$micronaut_load_class_value_2()})};
    }

* @since 4.6
*/
@NonNull
public static <E extends Enum<E>> EnumSet<E> enumSet(@NonNull E... enums) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add nullability annotations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What kind of nullability annotations?

AbstractInitializableBeanDefinition.PrecalculatedInfo.class, // precalculated info
Condition[].class, // pre conditions
Condition[].class, // post conditions
Throwable.class // failed initialization
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change this slightly to try lookup this constructor otherwise if not there fallback to the other constructor. Otherwise we will hit binary compatibility issues for all the modules again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will not break anything, that's the new super constructor. We have some modules that have been compiled with previous version and tests are passing.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes but if there is an old version of micronaut-inject then the lookup will fail which means we will have to release new versions of every minor release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How is it possible to have an older version of micronaut-inject? Inject and core-processor should always come with the same version.

Copy link
Contributor

Choose a reason for hiding this comment

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

@graemerocher
Copy link
Contributor

there seem to be some test failures

@graemerocher
Copy link
Contributor

@dstepanov pls address the sonar stuff before merging

Copy link

sonarcloud bot commented Jul 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
63.6% Coverage on New Code (required ≥ 70%)
6 New Critical Issues (required ≤ 0)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@dstepanov dstepanov merged commit 6f27055 into 4.6.x Jul 3, 2024
16 of 17 checks passed
@dstepanov dstepanov deleted the missingbeans branch July 3, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants