Questions tagged [null-check]

A check to see that an object has been instantiated.

A check to see that an object has been instantiated.

Typically, in a OO programming language, this is to see whether an object has been created or not.

e.g (Java example)

public void doStuff(Object obj) {
    if (obj != null) {
        // Do stuff with the object
    }
}
217 questions
0
votes
1 answer

kotlin safe and non-null operation

if (intent.extras?.getBoolean(AppConstants.KEY_IS_FROM_NOTIFICATION) == true) { val intent = Intent( this, SplashScreen::class.java ).apply { addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) …
Amit Yadav
  • 32,664
  • 6
  • 42
  • 57
0
votes
0 answers

How to update an existing data without interrupting all other data of a database table using ternary operator in c# dot net

I am creating a Web API which will do CRUD operation. I have defined all the methods to CRUD but I am facing an issue when I try to update a data in db then either I had to pass all columns data else it is updating the columns with null and I want…
0
votes
1 answer

EXCEPTION CAUGHT BY WIDGETS LIBRARY The following _CastError was thrown building: Null check operator used on a null value

I'm new to Flutter and I am getting this error: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following _CastError was thrown building: Null check operator used on a null value. I'm working…
0
votes
0 answers

Combining Optional.ofNullable() null check in java

I am doing a null check using Optional.ofNullable() for an API response where all the fields are optional (for lack of a better word), but we want to map the ones that are present, which may differ on each response…
0
votes
2 answers

can't resolve null value

enter image description here I am facing this error that Null check operatorr Null check operator used on a null value The relevant error-causing widget was: MaterialApp…
0
votes
1 answer

null check cant get out of this

guys ı cant get out of this .can you check and infor me about the place where ı should put null check . this for sharing the post for formality.ı didnt wanna determine the name age and salaray below. class _Employee { String? empName; int?…
said
  • 5
  • 5
0
votes
1 answer

Ruby's safe navigation operator (&.) not working as intended anymore after being in use on production code for years

I'm having this issue in production code that's been running for years without issue, where suddenly a lot of places where i use the &. operator is just crashing. So I'm wondering if it's not just an environment variable or some kind of interpreter…
0
votes
1 answer

Is there a performance difference between null-check and null-conditional-operator in C#?

I am wondering whether there is a difference in performance between these two if-statements: if(myObject != null && myObject.someBoolean) { // do something } if (myObject?.someBoolean ?? false) { // do something } If there is a difference…
0
votes
1 answer

Null check operator used on a null value, Flutter, State, LateInitializationError

A simple app which returns a TextButton() with given name and given color. Problem: I have to choose the color first and then name the card but can't name the card and then choose the color. I'd get an LateinitializationError with late String…
Val
  • 31
  • 1
  • 7
0
votes
2 answers

C# While Loop Null Check Pattern?

I wrote code like this using (var reader = new StreamReader("SomeFilePath")) { while(reader.ReadLine() is string currentLine) {} } Then My IDE Rider suggested me below with comment "Use null check pattern" using (var reader = new…
0
votes
1 answer

Using Supplier instead of Optional as a method parameter

I have an interface and its parameter can be null. int count(@Nullable F filter); To avoid null parameters and null-checks, common advice is to use the method overloading: int count(); int count(@NonNull F filter); In some cases, I don't like this…
Alexey
  • 104
  • 6
0
votes
3 answers

Sort a Java collection object based on one field in it and apply checks

retList.sort((comp1, comp2) -> compartmentOrderMap.get(comp2.getCompartment()).compareTo(compartmentOrderMap .get(comp1.getCompartment()))); I want to add a null check before comparing. How can I do that? retList.sort((comp1,…
0
votes
1 answer

Sum up Non-null properties of each object in a List using Java version greater then 8

Below is the simplified structure of my classes: public class Thing { private BigDecimal field1; private BigDecimal field2; private XYZ field3; private BigDecimal field4; } public class XYZ { private BigDecimal field5; …
Ankur Goel
  • 99
  • 1
  • 1
  • 7
0
votes
2 answers

How to null check object property with a variable

data, roles and infos are variables that came from an API, Here I manually add array's index whereas in my code I loop the keys. How to one line check if the attribute is null ? Is there a way to access property like x?[roles[0]]?[infos[0]] const…
CookieThief
  • 158
  • 2
  • 10
0
votes
1 answer

Kotlin cannot make out that I've already checked whether the item is in the collection

val map = mapOf( 'a' to 1, 'b' to 2, 'c' to 3 ) val c = 'a' if (c in map) { println(map[c] + 1) } In the simple code stub, Kotlin compiler does not allow me to perform the operation in println. It yells to me with the following…
ibrahim koz
  • 537
  • 4
  • 15