Compiler exception when subclassing WindowAdapter


#1

I encountred a problem when building a Swing application in Kotlin. I reduced it to a minimal test case which causes a compiler exception using M5.

import java.awt.event.*

class Foo() : WindowAdapter() {
  fun windowClosing(e : WindowEvent) {}
}


Additional information which may be helpful:

If “override” is added to the windowClosing function, it compiles and runs correctly.

The other 9 methods in WindowAdapter work without override. If override is added to any of them, there is a compiler error message about overridng “nothing”. I believe all the methods in WindowAdapter are concrete but empty.


#2

Try using WindowEvent? type or Press Ctrl + N and choose override.


#3

Dody, You are correct, changing to WindowEvent? produces a clean compile for the windowClosing function.

However, using WindowEvent? causes a compiler exception for the other methods. So now

class Foo() : WindowAdapter() {   fun windowOpened(e : WindowEvent?){} }

causes an exception, while with WindowEvent it works.

Clearly, something is broken and probably manifesting itself in multiple ways. Probably no need for further test cases. With a simple, repeatable test case, the bug should be easy to find.

Anyway, I have a workaround and am able to continue with my learning curve coding.


#4

The nullable works because by default Kotlin treats everything from the Java side as a potential nullable value (unless you annotate it otherwise).

The easiest path is to have the IDE to generate the override signature for you so it will work. This is where the ctrl + N comes in.


#5

Please, report bugs to the issue tracker. Thanks


#6

http://youtrack.jetbrains.com/issue/KT-3360