Object val field is initialized more than once


#1

I have an code that registeres an Stub index in custom idea plugin:

object RuleKeyIndex : StringStubIndexExtension<AlfaRuleEntry>() {
    val KEY : StubIndexKey<String, AlfaRuleEntry> = StubIndexKey.createIndexKey("alfa.Rule.index")
}

The issue is StubIndexKey.createIndexKey must not be called more than once with same parameter, but in the code above it actually does:
first time it is called with stack:

at com.intellij.psi.stubs.StubIndexKey.createIndexKey(StubIndexKey.java:34)
	  - locked <0x19de> (a java.lang.Class)
	  at com.dmgburg.alfa.stubs.RuleKeyIndex.<init>(RuleStubElementType.kt:55)
	  at com.dmgburg.alfa.stubs.RuleKeyIndex.<clinit>(RuleStubElementType.kt:54)
	  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-1)

and the second one is called with stack:

	  at com.intellij.psi.stubs.StubIndexKey.createIndexKey(StubIndexKey.java:34)
	  - locked <0x19de> (a java.lang.Class)
	  at com.dmgburg.alfa.stubs.RuleKeyIndex.<init>(RuleStubElementType.kt:55)
	  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-1)

I have worked around it with

 var KEY : StubIndexKey<String, AlfaRuleEntry>? = null

    init{
        if(KEY == null){
            KEY = StubIndexKey.createIndexKey("alfa.Rule.index")
        }
    }

but I wonder if such behavior was intended.