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
2 answers

macro wrapper for malloc pros and cons

I've always done checking what malloc returns like this: void *p; p = malloc(100); if (p) { perror("malloc"); return false; } But one thought, why do it if you can guarantee getting memory? #define GET_MEM(p,s,i)…
Ivan Ivanovich
  • 880
  • 1
  • 6
  • 15
0
votes
1 answer

Is this sharper than the Resharper Robots?

Resharper changed (with my approval, of course) this: private static Subdepartment GetSubdepartmentForXMLElement(XElement subdept) { return new Subdepartment { Id = Convert.ToInt32(subdept.Element("Id")), AccountId =…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
0
votes
1 answer

Runtime binding issue using Facebook OAuth

I implemented a login example using Facebook OAuth, but I ran into an issue after login credentials are input. One of the fields that are being pulled in to the TBInfos text box is causing a null reference due to possibly the user not having a value…
Brian Var
  • 6,029
  • 25
  • 114
  • 212
0
votes
1 answer

Null-checker in Java

I saw the following line of code in a project : if (null != policyProDO.getSelected()). I have never seen null on the left of assignment operator. I would rather write the above line of code as : if (policyProDO.getSelected() != null). What's really…
user3752273
  • 1
  • 1
  • 1
0
votes
3 answers

Should event firing in C# always be protected by a null check?

This situation seem very interesting to me. In C# you need to check if there is any listener to the event in a class before firing it. Assuming event structure of C# is a non-standart(Meaning Microsoft did it) implementation of Observer observable…
Ali Akdurak
  • 3,841
  • 1
  • 18
  • 16
0
votes
1 answer

Refactoring and removing if null checks in chain filtering

I'm doing some filtering on database entries and I ended up with somewhat ugly code, which I don't like. I have my MyFilterResolverFactory class where I build and return my MyFilterResolver chain. public abstract class MyFilterResolver { …
ioreskovic
  • 5,531
  • 5
  • 39
  • 70
0
votes
5 answers

Can I include null-checking an object as another conditional in OR statement?

Possible Duplicate: Is relying on && short-circuiting safe in .NET? I wasn't sure how to phrase the title of the question correctly, but it's very simple to explain with a single line of code: if (someObject == null || someObject.someProperty) …
anon
0
votes
1 answer

Is it better to check for null and return or check for non-null and continue?

Given the following basic class: public class MyClass { private object m_memberVariable; public MyClass() { this.m_memberVariable = new object(); } } Which of the following implementations of the test method is better…
gooch
  • 575
  • 5
  • 14
-1
votes
5 answers

Java reduce cognitive complexity of method which has multiple if statements

Hello I am looking for a way to reduce cognitive complexity of method which has multiple if statements. All are basically nullchecks for each item of object and is required. Code snippet: private void assignFruit(FruitBasket1 fruit1, FruitBasket2…
-1
votes
2 answers

Null-check for inherited member in TypeScript?

abstract class Base { protected id: number | null = null; init(id: number) { this.id = id; } isIdSet(_ = this.id): _ is null | never { if (this.id === null) throw new Error(ERROR_NO_ID); else return false; } } class Foo…
Pavel Staselun
  • 1,970
  • 1
  • 12
  • 24
-1
votes
4 answers

Check if document.GetElementById("").value does not contain null

I am trying to check below condition, var param= document.getElementById("txtbox").value; if(param!== null || param.length!==0 || param !=="" || param!==undefined) {//do something} but even if param is null it is entering in the if block. Does…
Faran Saleem
  • 404
  • 1
  • 7
  • 31
-1
votes
1 answer

java script or angularjs condition check on object with "!" vs "!!"

Can anyone explain, the difference between
and
I was wondering what !! does? in angularjs I googled it but didn't get relivent answer
-1
votes
1 answer

How to determine that a null character does not give an error in a sentence

** I wanted to check a sentence whether contains one null character between two words. I am new. So, there is not much of code samples for This problem. ** I used String.IsNullOrEmpty to determine the emptiness of the string. However, I did wrong.…
-1
votes
3 answers

How to get ride of Null check in singleton design pattern in Java for better performance

To ensure only one instance of the class get created in a multi-threaded environment, we create a singleton class with the below structure. class Singleton { private volatile static Singleton _instance; private Singleton() { //…
Arpan
  • 913
  • 2
  • 12
  • 19
-1
votes
2 answers

Why the overall performance of application degrades if I do null checks on the maps?

Below is my class which uses CountDownLatch to make sure reads are not happening on the primary, secondary and tertiary maps for the first time whenever writes are happening on those maps. public class ClientData { public static class Mappings…
john
  • 11,311
  • 40
  • 131
  • 251
1 2 3
14
15