Kotlin: generate static properties as get/set functions#1800
Merged
pwrobeldev merged 14 commits intomasterfrom Feb 19, 2026
Merged
Conversation
This commit showcases the runtime error related to usage of internal static property from Kotlin generated code. The current syntax for static internal properties does not guarantee that they work properly. It seems that combination of 'JvmName()' for property get/set and 'JvmStatic' does not work. The following runtime error is visible: ``` java.lang.NoSuchMethodError: 'java.lang.String com.here.android.test.InternalAttributeClassWithStaticProperty$Companion.getFooBar$functional_release()' at com.here.android.test.VisibilityAttributeTest.checkInternalStaticProperty(VisibilityAttributeTest.kt:205) ``` Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The usage of static property with annotations did not work for internal static properties in Kotlin. This is fixed by representing properties via get/set functions. The additional extension functions for static properties are removed, because they are not needed -- functions are used by default. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Showcase that after the fix the code works as expected. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
890800e to
14e8936
Compare
This commit ensures that definition of 'InternalClassWithStaticProperty' is identical in both smoke and functional tests. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The static properties in interfaces can use 'internal' and JvmSynthetic. Moreover, the 'Impl' class uses wrong syntax -- ordinary static properties instead of get/set function. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Such properties when internal should not be accessible from Java and should use 'internal' and 'JvmSynthetic' keywords. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change reworks handling of static properties in interfaces. The getter/setter is used in the impl class. Moreover, the code is simplified by including 'KotlinFunction.mustache'. The 'JvmSynthetic' is properly generated now. One missing piece is 'internal' keyword -- it will be added in upcoming change. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Because of the previous change the test stopped to compile as expected.
JvmSynthetic hides the getter/setter of internal static property for interface
from Java.
```
> Task :functional:compileReleaseUnitTestJavaWithJavac FAILED
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:126: error: cannot find symbol
assertEquals("FOO_BAR", InternalAttributeInterfaceParent.getSomeInternalProperty());
^
symbol: method getSomeInternalProperty()
location: interface InternalAttributeInterfaceParent
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:128: error: cannot find symbol
InternalAttributeInterfaceParent.setSomeInternalProperty("abc");
^
symbol: method setSomeInternalProperty(String)
location: interface InternalAttributeInterfaceParent
/functional/android/src/test/java/com/here/android/test/VisibilityAttributeTest.java:129: error: cannot find symbol
assertEquals("abc", InternalAttributeInterfaceParent.getSomeInternalProperty());
^
symbol: method getSomeInternalProperty()
location: interface InternalAttributeInterfaceParent
```
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
'JvmStatic' annotation cannot be used for non-public members of companion object in interfaces. The following error was observed when I tried to add 'internal' keyword to such static elements: ``` Only public members in interface companion objects can be annotated with '@JvmStatic' ``` Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Hsilgos
previously approved these changes
Feb 19, 2026
It seems that this usage fails for Java generator and its tests. This is not critical for Kotlin generator. It will be handled in a separate ticket. Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Hsilgos
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
---------- Motivation ----------
During internal testing I found that
static internal propertiesdo not work correctly.Basically, the combination of
JvmStatic property + JvmName for get/setsometimes isnot correctly resolved in runtime.
Moreover, I identified the gap related to internal static properties and functions in interfaces.
Even though companion object of interface allows usage of
internalkeyword, we cannot useJvmStatic. Therefore, such usage must be flagged during validation.---------- Solution ----------
A note before showing design decision:
because of similar problems
to preserve compatibility with Java
Because of that and the problem stated in 'Motivation' section, the static properties in classes
are also handled using get/set function pair. This way internal static properties work as expected.
This commit additionally removes the generation of extension functions because they are not needed
now. Furthermore, validation of LimeInterface in Kotlin is adjusted to disallow static internal properties
and functions.