Skip to content

Empty Kotlin SourceFileSet is passed to JavaPrinter #17

Open
SpineEventEngine/ProtoData
#173
@alexander-yevsyukov

Description

@alexander-yevsyukov

If Kotlin is enabled in a project it causes current language filtering fail because an empty Kotlin-based set is still passed to a JavaPrinter.

It can be reproduced in protodata-extension/.../UuidJavaRenderer.java class. The PR SpineEventEngine/ProtoData#87 added a forced check to quit the printing if a file isn't found. If you remove the check the tests would fail with the following diagnostics:

> Task :consumer:launchProtoDataMain FAILED
Exception in thread "main" java.lang.IllegalArgumentException: File not found: `io/spine/protodata/test/ProjectId.java`. 
Source root: `/Users/sanders/Projects/Spine/ProtoData/tests/consumer/build/generated-proto/main/kotlin`. 
Target root: `/Users/sanders/Projects/Spine/ProtoData/tests/consumer/generated/main/kotlin`.
        at io.spine.protodata.renderer.SourceFileSet.file$lambda$2(SourceFileSet.kt:131)
        at java.base/java.util.Optional.orElseThrow(Optional.java:408)
        at io.spine.protodata.renderer.SourceFileSet.file(SourceFileSet.kt:130)
        at io.spine.protodata.test.uuid.UuidJavaRenderer.render(UuidJavaRenderer.java:93)
        at io.spine.protodata.renderer.Renderer.renderSources$compiler(Renderer.kt:54)

As you can see from the above error, the file which is attempted to be found is .java, while source- and target roots are under main/kotlin.

This happens because UuiRenderer attempts to find ProjectId.java (which name it calculates from a proto type name) under a directory with generated Kotlin code.

Presumably, the root cause is that Renderer.renderSources() creates an empty set (when all .kt files are not matched to .java), and then the empty set is passed to UuidJavaRenderer.render().

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions