Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper varargs check in KeyValues and Tags #3851

Closed
jonatan-ivanov opened this issue May 19, 2023 · 0 comments
Closed

Improper varargs check in KeyValues and Tags #3851

jonatan-ivanov opened this issue May 19, 2023 · 0 comments
Labels
bug A general bug module: micrometer-common An issue that is related to our common module module: micrometer-core An issue that is related to our core module
Milestone

Comments

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented May 19, 2023

If I do this:

KeyValue kv = null;
KeyValues.of("a", "1").and(kv);

I get an NPE since in case of varargs:

KeyValues and(@Nullable KeyValue... keyValues) {

this is not a proper check:

if (keyValues == null || keyValues.length == 0)

KeyValues.of(null) will result in an empty keyValues array that has one null element in the and method which passes the check.
Maybe this can be just a documentation issue and we should state that null elements are not allowed without checking.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "a[runHi]" is null
	at java.base/java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
	at java.base/java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
	at java.base/java.util.Arrays.sort(Arrays.java:1041)
	at io.micrometer.common.KeyValues.<init>(KeyValues.java:47)
	at io.micrometer.common.KeyValues.and(KeyValues.java:107)
	at io.micrometer.core.samples.Sample.main(Sample.java:24)

Since KeyValues is basically a copy of Tags, Tags has the same issue.

Discovered based on #3849 by @dietzsch

@jonatan-ivanov jonatan-ivanov added bug A general bug module: micrometer-core An issue that is related to our core module module: micrometer-common An issue that is related to our common module labels May 19, 2023
@jonatan-ivanov jonatan-ivanov added this to the 1.9.12 milestone May 19, 2023
jonatan-ivanov added a commit that referenced this issue Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug module: micrometer-common An issue that is related to our common module module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

No branches or pull requests

1 participant