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

NullPointerException crash in Java API #3729

Closed
njbartlett opened this Issue Jan 24, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@njbartlett
Copy link

njbartlett commented Jan 24, 2018

In the Java API, the following code works:

private final Gauge fillLevelGauge = Gauge.build()
        .name("fill_level")
        .help("Fill level")
        .register();

    // ...

    fillLevelGauge.set(1d);

... but the following code crashes with a NullPointerException:

private final Gauge fillLevelGauge = Gauge.build()
        .name("fill_level")
        .labelNames("mylabel")
        .help("Fill level")
        .register();

    // ...

    fillLevelGauge.set(1d);

I found the following issue which states "for a labelled metric you must specify the labels". However I cannot believe that you actually intend for the program to crash when a programmer makes this mistake? And not even with any explanation of the reason for the crash?

At the very least I believe this should be an IllegalArgumentException with a message attached, e.g. "for a labelled metric you must specify the labels".

@krasi-georgiev

This comment has been minimized.

Copy link
Member

krasi-georgiev commented Jan 24, 2018

@njbartlett shouldn't this be in the java client issues?
https://github.com/prometheus/client_java

@njbartlett

This comment has been minimized.

Copy link
Author

njbartlett commented Jan 24, 2018

@krasi-georgiev Sorry yes, I will move it.

@njbartlett njbartlett closed this Jan 24, 2018

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 23, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.