Skip to content

StackOverflowError when OS has a lot of environment variables #700

@extbe

Description

@extbe

Hi!

Versions
config v1.4.0
Java 11.0.2

Description
I try to run my application on OS with about 700 environment variables. I have a config file with substitution test = ${ENV_VARIABLE} and next code to create Config:

Config conf = ConfigFactory.systemProperties()
                .withFallback(ConfigFactory.parseResources("test.conf"))
                .withFallback(ConfigFactory.systemEnvironment())
                .resolve();

Also I limit thread stack size to 210k using -Xss210k, so the application fails with an error (I skipped the rest of stack trace because it is about 900 lines long)

Exception in thread "main" java.lang.StackOverflowError
	at java.base/java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1041)
	at java.base/java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1041)
	at java.base/java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1042)
	at java.base/java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1041)
	at java.base/java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1042)
	at java.base/java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1041)
	at java.base/java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1042)
	at java.base/java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1041)

I noticed that if I remove the substitution or .withFallback(ConfigFactory.systemEnvironment()) then the application starts.

I debugged and found that in the ResolveContext each call to pushTrace or popTrace wraps cycleMarkers into another UnmodifiableSet (because the constructor does it), even though it's already an UnmodifiableSet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions