Repository: JetBrains/kotlin
File: compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmReflectSymbols.kt (Kotlin)

Code before:
                addValueParameter("receiver", irBuiltIns.anyNType)
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(irBuiltIns.anyNType)
                    varargElementType = irBuiltIns.anyNType
                }
            }
        }

    val javaLangReflectConstructor: IrClassSymbol =
        createJavaLangReflectClass(FqName("java.lang.reflect.Constructor")) { klass ->
            klass.addFunction("setAccessible", irBuiltIns.unitType).apply {
                addValueParameter("isAccessible", irBuiltIns.booleanType)
            }
            klass.addFunction("newInstance", irBuiltIns.anyNType).apply {
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(irBuiltIns.anyNType)
                    varargElementType = irBuiltIns.anyNType
                }
            }
        }

    init {
        val klass = context.ir.symbols.javaLangClass.owner
        if (!klass.functions.any { it.name.asString() == "getDeclaredMethod" }) {
            klass.addFunction("getDeclaredMethod", javaLangReflectMethod.defaultType.makeNullable()).apply {
                addValueParameter("methodName", irBuiltIns.stringType.makeNullable())
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(klass.defaultType).makeNullable()
                    varargElementType = klass.defaultType
                }
            }
            klass.addFunction("getDeclaredField", javaLangReflectField.defaultType).apply {
                addValueParameter("fieldName", irBuiltIns.stringType)
            }
            klass.addFunction("getDeclaredConstructor", javaLangReflectConstructor.defaultType.makeNullable()).apply {
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(klass.defaultType).makeNullable()
                    varargElementType = klass.defaultType
                }
            }
        }
    }

    val javaLangReflectFieldSetAccessible: IrSimpleFunctionSymbol =
        javaLangReflectField.functionByName("setAccessible")

    val javaLangReflectMethodSetAccessible: IrSimpleFunctionSymbol =

Review comment (suggestion):
@udalov Is this "too defensive"? What I am thinking is by doing this mutation of JvmSymbols, I guess it's possible to create an inconsistent state if `JvmReflectSymbols` is instantiated a number of times.

Code after:
                addValueParameter("receiver", irBuiltIns.anyNType)
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(irBuiltIns.anyNType)
                    varargElementType = irBuiltIns.anyNType
                }
            }
        }

    val javaLangReflectConstructor: IrClassSymbol =
        createJavaLangReflectClass(FqName("java.lang.reflect.Constructor")) { klass ->
            klass.addFunction("setAccessible", irBuiltIns.unitType).apply {
                addValueParameter("isAccessible", irBuiltIns.booleanType)
            }
            klass.addFunction("newInstance", irBuiltIns.anyNType).apply {
                addValueParameter {
                    name = Name.identifier("args")
                    type = irBuiltIns.arrayClass.typeWith(irBuiltIns.anyNType)
                    varargElementType = irBuiltIns.anyNType
                }
            }
        }

    init {
        val klass = context.ir.symbols.javaLangClass.owner
        klass.addFunction("getDeclaredMethod", javaLangReflectMethod.defaultType.makeNullable()).apply {
            addValueParameter("methodName", irBuiltIns.stringType.makeNullable())
            addValueParameter {
                name = Name.identifier("args")
                type = irBuiltIns.arrayClass.typeWith(klass.defaultType).makeNullable()
                varargElementType = klass.defaultType
            }
        }
        klass.addFunction("getDeclaredField", javaLangReflectField.defaultType).apply {
            addValueParameter("fieldName", irBuiltIns.stringType)
        }
        klass.addFunction("getDeclaredConstructor", javaLangReflectConstructor.defaultType.makeNullable()).apply {
            addValueParameter {
                name = Name.identifier("args")
                type = irBuiltIns.arrayClass.typeWith(klass.defaultType).makeNullable()
                varargElementType = klass.defaultType
            }
        }
    }

    val javaLangReflectFieldSetAccessible: IrSimpleFunctionSymbol =
        javaLangReflectField.functionByName("setAccessible")

    val javaLangReflectMethodSetAccessible: IrSimpleFunctionSymbol =
        javaLangReflectMethod.functionByName("setAccessible")