NullPointerException in Java API
See original GitHub issueIn 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”.
NB PLEASE don’t just close this with your common response to ask questions in the user mailing list. This is not a usage question, I am reporting an actual bug in the software.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
NullPointerException (Java Platform SE 7 ) - Oracle Help Center
Thrown when an application attempts to use null in a case where an object is required. These include: ... Applications should throw instances...
Read more >java - What is a NullPointerException, and how do I fix it?
NullPointerException s are exceptions that occur when you try to use a reference that points to no location in memory ...
Read more >Java NullPointerException - Detect, Fix, and Best Practices
NullPointerException is a runtime exception, so we don't need to catch it in the program. NullPointerException is raised in an application when ...
Read more >Handling Java NullPointerException and Best Practices
Java NullPointerException is an unchecked exception and extends RuntimeException. Learn why NullPointerException occur and how to handle it ...
Read more >How to resolve the java.lang.NullPointerException - Educative.io
In Java, the java.lang.NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My fix will be roughly as follows:
SimpleCollector#noLabelsChild
private.SimpleCollector
calledgetNoLabelsChild
, in which the null check andthrow new IllegalArgumentException
occurs.SimpleCollector
subclasses accessnoLabelsChild
via that method.The getter method will likely be rapidly inlined by Hotspot so I do not believe any noticeable performance degradation would occur.
For those who tired to investigate problem root. This feature allows to add few series in one gauge.
you will get