I am encountering an issue with Kotlin (version 1.5.31) and how it accesses Java class properties. My kotlin class is using Eclipse SWT, specifically the class org.eclipse.swt.graphics.FontData and the name property in FontData. The issue is that the Linux implementation of SWT has a public name field as well as a public getter and setter for the name field. The getter is a simple getter, returning the name field. In contrast the Windows implementation of FontData only has the getter and setter for name, IE. it does not have the public name field.
My kotlin class uses property notation (IE. fontData.name) to access the name property of the FontData class. When compiling my class on Linux, it seems like Kotlin optimises the bytecode so as to access the public name field of FontData directly. When compiling my class on Windows against the Windows SWT jar, Kotlin produces bytecode calling getname().
This gives me a problem as my CI/CD server compiles using a Linux docker image and the Linux SWT jar. Any Windows user of my application gets a java.lang.NoSuchFieldError as the Windows SWT does not have the name field in FontData.
Is there any way to disambiguate whether Kotlin should use the public field or the getter when both exist? I have tried changing my Kotlin code to use the getter (IE. fontData.getName()) but that still gets optimised by the Kotlin compiler to use the name field directly. Is this a bug in the Kotlin compiler?