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

Fix compilation error on Windows #764

Merged
merged 3 commits into from Feb 24, 2020
Merged

Fix compilation error on Windows #764

merged 3 commits into from Feb 24, 2020

Conversation

TWiStErRob
Copy link
Contributor

@TWiStErRob TWiStErRob commented Feb 20, 2020

Description

Fix this compilation error on Windows:

java.io.FileNotFoundException: P:\projects\contrib\github-neo4j-ogm\neo4j-ogm-tests\neo4j-ogm-integration-tests\target\test-classes\org\neo4j\ogm\kotlin\KotlinMetaDataTest$Kotlin's "implementation by delegation" should yield same result as Java equivalent$1.class (The filename, directory name, or volume label syntax is incorrect)

[click to expand]

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.61:test-compile (test-compile) on project neo4j-ogm-integration-tests: Compilation failure
[ERROR] java.lang.IllegalStateException: Backend Internal error: Exception during code generation
[ERROR] File being compiled at position: file://P:/projects/contrib/github-neo4j-ogm/neo4j-ogm-tests/neo4j-ogm-integration-tests/src/test/kotlin/org/neo4j/ogm/kotlin/KotlinMetaDataTest.kt
[ERROR] The root cause java.io.FileNotFoundException was thrown at: java.io.FileOutputStream.open0(Native Method)
[ERROR]         at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:35)
[ERROR]         at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:76)
[ERROR]         at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:96)
[ERROR]         at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
[ERROR]         at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
[ERROR]         at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:637)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:195)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
[ERROR]         at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
[ERROR]         at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
[ERROR]         at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
[ERROR]         at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execCompiler(KotlinCompileMojoBase.java:228)
[ERROR]         at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:237)
[ERROR]         at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:55)
[ERROR]         at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute(KotlinCompileMojoBase.java:209)
[ERROR]         at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute(K2JVMCompileMojo.java:222)
[ERROR]         at org.jetbrains.kotlin.maven.KotlinTestCompileMojo.execute(KotlinTestCompileMojo.java:84)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]         at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
[ERROR]         at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
[ERROR]         at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:61)
[ERROR] Caused by: java.io.FileNotFoundException: P:\projects\contrib\github-neo4j-ogm\neo4j-ogm-tests\neo4j-ogm-integration-tests\target\test-classes\org\neo4j\ogm\kotlin\KotlinMetaDataTest$Kotlin's "implementation by delegation" should yield same result as Java equivalent$1.class (The filename, directory name, or volume label syntax is incorrect)
[ERROR]         at java.io.FileOutputStream.open0(Native Method)
[ERROR]         at java.io.FileOutputStream.open(FileOutputStream.java:270)
[ERROR]         at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
[ERROR]         at com.intellij.openapi.util.io.FileUtil.writeToFile(FileUtil.java:1057)
[ERROR]         at com.intellij.openapi.util.io.FileUtil.writeToFile(FileUtil.java:1051)
[ERROR]         at com.intellij.openapi.util.io.FileUtil.writeToFile(FileUtil.java:1036)
[ERROR]         at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:32)
[ERROR]         at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo(outputUtils.kt:37)
[ERROR]         at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:41)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.writeOutput(KotlinToJVMBytecodeCompiler.kt:102)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.access$writeOutput(KotlinToJVMBytecodeCompiler.kt:82)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:111)
[ERROR]         at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
[ERROR]         at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:354)
[ERROR]         at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:353)
[ERROR]         at org.jetbrains.kotlin.codegen.state.GenerationState.afterIndependentPart(GenerationState.kt:310)
[ERROR]         at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:69)
[ERROR]         ... 46 more

I'm guessing it only applies to Windows, otherwise CI would be failing left and right.

Related Issue

See https://discuss.kotlinlang.org/t/more-characters-allowed-for-identifiers-than-grammar-specifies-what-is-supported/2359/4. An alternative fix would've been to change " to ', but I like the method name, so I opted to fix the root cause.
For some (probably historical) reason .stream() was used to generate a list of fields to be verified. This is ok, but Stream.map is a Java function and there's a Kotlin SAM conversion taking place when it is passed a { it.name } which means that an anonymous local inner class is being created. Local classes have the quirk of including not only the outer class name, but also the method name. Which means that the full .class file name includes the quotes.
To alleviate this simply removing the .stream() call forces Kotlin to compile against Iterable<T>.map which is a Kotlin extension function and is inline so there's no extra class created for the lambda, just a for loop.

Motivation and Context

I tried to run mvnw verify on my computer and got a compilation error in KotlinMetaDataTest.kt.

How Has This Been Tested?

The test compiles and runs green after this change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@michael-simons
Copy link
Collaborator

Thank you so much for this. This is a no-brainer to merge, but I need to ask you to sign our CLA.

https://neo4j.com/developer/cla/

Thank you!

@TWiStErRob
Copy link
Contributor Author

Sent mail to cla@...

@michael-simons michael-simons merged commit edb11e2 into neo4j:master Feb 24, 2020
michael-simons pushed a commit that referenced this pull request Feb 24, 2020
* Remove Java stream() to use `Iterable<T>.map` instead
* Format Java and Kotlin assertions in a similar way (using local too)
* Remove unnecessary inferred generics
@TWiStErRob TWiStErRob deleted the twisterrob/windows_compilation branch August 28, 2021 11:10
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.

None yet

2 participants