1

NOTICE

TLDR; I discovered that this was simply an environmental problem. The JAR with the kotlin code had old class files that caused unexpected problems that the compiler was 100% handling correctly.

I think that there was another class file in the JAR that I was trying to depend upon that was called SimpleLink that was a class instead of an interface. The Gradle Kotlin compile plugin didn't remove these classes when I removed the .kt files. LPT: Run the Gradle clean task before trying to publish, even if you are only publishing to maven local.


I'm having a problem with aspectj linking against code that uses kotlin classes from another project.

The aspectJ compiler is running version 1.8.6.

My particular problem is that, I keep seeing this: Type mismatch: cannot convert from element type ExtendedSimpleLink to SimpleLink

I have a type hierarchy where ExtendedSimpleLink extends LinkDecorator where LinkDecorator is written in kotlin and compiled in another project and ExtendedSimpleLink is java compiled with the aspectj compiler.

LinkDecorator looks like this:

abstract class LinkDecorator(
    private val decorated : SimpleLink
) : SimpleLink by decorated {
    override fun hashCode(): Int = decorated.hashCode()

    override fun equals(other: Any?): Boolean = decorated == other
}

I have no idea why the aspectj compiler can't figure out the type hierarchy. It should be looking at the bytecode for LinkDecorator and saying that obviously ExtendedSimpleLink is an instance of a SimpleLink.

As an example, the following code (trying to be compiled by the aspectJ compiler):

final class ExtendedSimpleLink extends LinkDecorator
{

    private final Double something;

    private final Object somethingElse;


    private ExtendedSimpleLink(
            final SimpleLink decorated,
            final Object somethingElse,
            final Double something)
    {
        super(decorated);
        this.somethingElse = somethingElse;
        this.something = something;
    }


    public static ExtendedSimpleLink from(final SimpleLink decorated)
    {
        if (decorated instanceof ExtendedSimpleLink)
        {
            return (ExtendedSimpleLink) decorated;
        }
        return new ExtendedSimpleLink(decorated, null, null);
    }
}

Compiling the above class gives this error from maven:

[ERROR] /Users/[user]/work/tmp/[project]/Core/src/main/java/com/company/core/engine/fitting/ExtendedSimpleLink.java:50:0::0 The return type is incompatible with LinkDecorator.getFabricLinkMetricEnhancement()
[ERROR] error at if (decorated instanceof ExtendedSimpleLink)
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] /Users/[user]/work/tmp/[project]/Core/src/main/java/com/company/core/engine/fitting/ExtendedSimpleLink.java:58:0::0 Incompatible conditional operand types SimpleLink and ExtendedSimpleLink
[ERROR] error at return (ExtendedSimpleLink) decorated;
[ERROR] ^^^^^^^^^^^^^^^^^

IntelliJ seems completely fine with this code. I think that it using the JavaC compiler for linting however.

My questions are, why is this happening? Is there a known problem in the AspectJ compiler? Are there similar problems with interop with groovy and the aspectJ compiler for example?

Update

I've tried adding the following to see if it solves the problem:

final class ExtendedSimpleLink extends LinkDecorator implements SimpleLink {
    // same as above...
}

Now I have all the same exceptions as before but with a new exception added to the mix:

[ERROR] error at final class ExtendedSimpleLink extends LinkDecorator implements SimpleLink
[ERROR] ^^^^^^^^^
[ERROR] /Users/[user]/work/tmp/[project]/Core/src/main/java/com/company/core/engine/fitting/ExtendedSimpleLink.java:23:0::0 The type SimpleLink cannot be a superinterface of ExtendedSimpleLink; a superinterface must be an interface
Jonathan Leitschuh
  • 822
  • 1
  • 8
  • 29

0 Answers0