Skip to content

ClassCastException when reading environment properties #2348

@UpcraftLP

Description

@UpcraftLP

Describe the bug
When reading environment properties, Koin assumes that all properties are strings.

val propertiesMapValues = properties.toMap() as Map<String, String>

However, due to legacy java API weirdness, this is not guaranteed to be the case, and both keys and values could be arbitrary objects.

Therefore when Koin does the hard cast to strings, the application might crash.

To Reproduce

  1. Set non-string properties via System.setProperties()
  2. Start Koin framework

Expected behavior
Koin starts up fine, ignoring any invalid properties.

Koin module and version:
koin-core-jvm:4.0.4

Snippet or Sample project to help reproduce

var properties = new Properties();

// save existing properties just in case
properties.putAll(System.getProperties());

// intentionally malformed input
properties.put(new Object(), new Object());

// just replace the existing map
System.setProperties(properties);

// start Koin.....

ref: Up-Mods/HT_DiscordBridge#4
ref: Up-Mods/HT_DiscordBridge#6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions