[JAVA-3884] Coverity analysis defect 116506: Dereference null return value Created: 05/Nov/20  Updated: 27/Oct/23  Resolved: 25/Nov/20

Status: Closed
Project: Java Driver
Component/s: Internal
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Dereference null return value

If the function actually returns a null value, a NullPointerException will be thrown. Return value of function which returns null is dereferenced without checking
/bson/src/main/org/bson/codecs/pojo/PojoBuilderHelper.java:121: NULL_RETURNS 116506 "getSuperclass" returns "null" (checked 2 out of 9 times).
/bson/src/main/org/bson/codecs/pojo/PojoBuilderHelper.java:121: NULL_RETURNS 116506 Assigning: "currentClass" = "null" return value from "getSuperclass".
/bson/src/main/org/bson/codecs/pojo/PojoBuilderHelper.java:58: NULL_RETURNS 116506 Calling a method on null object "currentClass".



 Comments   
Comment by Jeffrey Yemin [ 25/Nov/20 ]

Coverity doesn't realize that we're dealing with a class hierarchy and that the value of Class.getSuperclass for any given instance of Class can't change. So once we check that getSuperclass is not null, we know that it will remain not null.

Comment by Coverity Collector User [ 05/Nov/20 ]

A new defect has been detected and assigned to jeff.yemin in Coverity Connect.
http://coverity.mongodb.com/query/defects.htm?project=Java+Driver&cid=116506
The defect was flagged by checker NULL_RETURNS in
file /bson/src/main/org/bson/codecs/pojo/PojoBuilderHelper.java
function org.bson.codecs.pojo.PojoBuilderHelper.configureClassModelBuilder(org.bson.codecs.pojo.ClassModelBuilder, java.lang.Class)
and this ticket was created by milkie

Generated at Thu Feb 08 09:00:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.