Skip to content
Advertisement

Tag: null

Exceptions or null in java

I have the next doubt. According to good practices of java, how to manage the cases in which the object can not be found and we want to know why. For example, if someone has problems logging in our system and we want to inform them exactly what is the problem, we cannot return null because we lose the reason

How to resolve findbug issue: Null passed for nonnull parameter

I’m getting the following findbugs error: “Method call passes null for nonnull parameter : Null passed for nonnull parameter of getApiStatus(ApiResponse)” If the apiResponse is null in the CallApi method (not shown here for brevity’s sake), it simply throws an exception that is caught in handleApiException and thrown again if we can’t do anything else about the exception. There is

Why the if condition runs the other way

the value passed fromjsonObject.getString(“firstName”); to firstNameValidateUser is null as it doesn’t have any value, I need to run the following code which contain String firstName=jsonObject.getString(“firstName”);…. till returnedUser = new User(firstName, lastName, user.userName, user.password, birthDate, position,qualification,email); when the value of firstNameValidateUser is null. How do I check it,I have used the if condition to check if the firstNameValidateUseris null ,but from

How to check a Long for null in java

How do I check a Long value for null in Java? Will this work? Answer Primitive data types cannot be null. Only Object data types can be null. There are 8 primitive types in Java: Data Type Size Description byte 1 byte Int8 short 2 bytes Int16 int 4 bytes Int32 long 8 bytes Int64 float 4 bytes Single double

Sum with Integer object if not null

I do not know if it is possible in Java but I need a method to do a special “add function”. Let me explain, SHORT VERSION: Is it possible to add an int with an Integer object? I need a method to check if that integer object exists, and add 0 if the object is null, add the correct value

Why is my Spring @Autowired field null?

Note: This is intended to be a canonical answer for a common problem. I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try to use it. The logs show that both the MileageFeeCalculator bean and the MileageRateService bean are being created, but I get a NullPointerException whenever I try

How to do method overloading for null argument?

I have added three methods with parameters: When I am calling doSomething(null) , then compiler throws error as ambiguous methods. So is the issue because Integer and char[] methods or Integer and Object methods? Answer Java will always try to use the most specific applicable version of a method that’s available (see JLS ยง15.12.2). Object, char[] and Integer can all

Checking for a null int value from a Java ResultSet

In Java I’m trying to test for a null value, from a ResultSet, where the column is being cast to a primitive int type. From the code fragment above, is there a better way to do this, and I assume that the second wasNull() test is redundant? Educate us, and Thanks Answer The default for ResultSet.getInt when the field value

Advertisement