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

ModuleInfoDescriptorBlueprint.mergeCreate fails #7375

Closed
romain-grecourt opened this issue Aug 14, 2023 · 1 comment · Fixed by #7361
Closed

ModuleInfoDescriptorBlueprint.mergeCreate fails #7375

romain-grecourt opened this issue Aug 14, 2023 · 1 comment · Fixed by #7361
Assignees
Labels
4.x Version 4.x build declarative Helidon Declarative
Milestone

Comments

@romain-grecourt
Copy link
Contributor

  • Helidon Version: 4.0.0-M1

Compilation failed on ModuleInfoDescriptorBlueprint.mergeCreate without any code changes (main branch at e65fef5).

Error while processing: io.helidon.inject.tools.ToolsException: Error during codegen @ java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100) in ConfigDrivenProcessor
	at io.helidon.inject.processor.InjectionAnnotationProcessor.doProcess(InjectionAnnotationProcessor.java:217)
	at io.helidon.inject.processor.InjectionAnnotationProcessor.process(InjectionAnnotationProcessor.java:173)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1021)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.runContributingProcs(JavacProcessingEnvironment.java:857)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1263)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1402)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1271)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:948)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:82)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess0(JavacCompiler.java:700)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcessWithProperClassloader(JavacCompiler.java:681)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:670)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:187)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1140)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:193)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:294)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: io.helidon.inject.tools.ToolsException: Error during codegen
	at io.helidon.inject.processor.InjectionAnnotationProcessor.doFiler(InjectionAnnotationProcessor.java:308)
	at io.helidon.inject.processor.InjectionAnnotationProcessor.doProcess(InjectionAnnotationProcessor.java:205)
	... 40 more
Caused by: io.helidon.inject.tools.ToolsException: Error writing resource file: Index -1 out of bounds for length 12
	at io.helidon.inject.tools.CodeGenFiler.codegenResourceFilerOut(CodeGenFiler.java:521)
	at io.helidon.inject.tools.CodeGenFiler.codegenResourceFilerOut(CodeGenFiler.java:254)
	at io.helidon.inject.tools.CodeGenFiler.codegenModuleInfoFilerOut(CodeGenFiler.java:360)
	at io.helidon.inject.tools.ActivatorCreatorDefault.codegenModuleInfoFilerOut(ActivatorCreatorDefault.java:492)
	at io.helidon.inject.tools.ActivatorCreatorDefault.codegen(ActivatorCreatorDefault.java:401)
	t io.helidon.inject.tools.ActivatorCreatorDefault.createModuleActivators(ActivatorCreatorDefault.java:330)
	at io.helidon.inject.processor.CreatorHandler.createModuleActivators(CreatorHandler.java:54)
	at io.helidon.inject.processor.InjectionAnnotationProcessor.doFiler(InjectionAnnotationProcessor.java:296)
	... 41 more
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 12
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.util.Objects.checkIndex(Objects.java:385)
	at java.base/java.util.ArrayList.remove(ArrayList.java:551)
	at io.helidon.inject.tools.ModuleInfoDescriptorBlueprint.mergeCreate(ModuleInfoDescriptorBlueprint.java:155)
	at io.helidon.inject.tools.CodeGenFiler.lambda$codegenModuleInfoFilerOut$0(CodeGenFiler.java:355)
	at io.helidon.inject.tools.CodeGenFiler.codegenResourceFilerOut(CodeGenFiler.java:502)
	... 48 more

The impacted module is helidon-integrations-oci-sdk-runtime and the module-info looks like this:

module io.helidon.integrations.oci.sdk.runtime {

    //...
    uses io.helidon.inject.api.ModuleComponent;

    provides io.helidon.inject.api.ModuleComponent with
            io.helidon.integrations.oci.sdk.runtime.Injection$$Module;
}

ModuleInfoDescriptorBlueprint.mergeCreate compares two module-info by finding matching "items":

default ModuleInfoDescriptor mergeCreate(ModuleInfoDescriptor another) {
    if (another == this) {
        throw new IllegalArgumentException("can't merge with self");
    }

    ModuleInfoDescriptor.Builder newOne = ModuleInfoDescriptor.builder((ModuleInfoDescriptor) this);
    for (ModuleInfoItem itemThere : another.items()) {
        Optional<ModuleInfoItem> itemHere = first(itemThere.target());
        if (itemHere.isPresent()) {
            int index = newOne.items().indexOf(itemHere.get());
            newOne.items().remove(index);
            ModuleInfoItem mergedItem = itemHere.get().mergeCreate(itemThere);
            newOne.items().add(index, mergedItem);
        } else {
            newOne.addItem(itemThere);
        }
    }

    return newOne.build();
}

See above first(itemThere.target()):

default Optional<ModuleInfoItem> first(String target) {
    return items().stream()
            .filter(it -> it.target().equals(target))
            .findFirst();
}

This means that uses io.helidon.inject.api.ModuleComponent is matchable with:

provides io.helidon.inject.api.ModuleComponent with
        io.helidon.integrations.oci.sdk.runtime.Injection$$Module;

When the item is wrongly matched, the next iteration with the correct match throws an error the code does .remove(-1).


The real issue is that items can't be compared just by "target", uses io.helidon.inject.api.ModuleComponent != provides io.helidon.inject.api.ModuleComponent with xxx.

The code needs to match items of the same kind.

@romain-grecourt romain-grecourt added build 4.x Version 4.x declarative Helidon Declarative labels Aug 14, 2023
@romain-grecourt romain-grecourt added this to the 4.0.0-M2 milestone Aug 14, 2023
@romain-grecourt
Copy link
Contributor Author

CC @trentjeff @tomas-langer

@romain-grecourt romain-grecourt linked a pull request Aug 16, 2023 that will close this issue
@romain-grecourt romain-grecourt self-assigned this Aug 16, 2023
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x build declarative Helidon Declarative
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant