Questions tagged [nullable]

The nullable tag is for issues relating to nullable members or types. A null is used to represent a missing or unknown value.

A data member is nullable if it can have the special value of NULL, instead of their common range of possible values. Nullable types are a feature of some statically-typed programming languages.

.NET

In , the built-in generic type System.Nullable<T> allows the programmer to use value types like int or DateTime with a value of null. Several .NET languages have a special syntax for declaring Nullable:

  • In , int? is an alias for System.Nullable<System.Int32>
  • In , Integer? is an alias for System.Nullable(Of System.Int32)

SQL

Null is a special marker used in SQL to indicate that data value do not exist in the database. Its proper use ensures various statistical aggregate functions perform correctly.

See more on Wikipedia.

D

The typecons module in package std has a templated struct - Nullable - for wrapping values types and allowing them to appear to have a null value (as in C#). Restriction is that the type must be able to be instantiated with T var or T var = T.init, where T represents the type being used.

Related tags

2417 questions
1
vote
1 answer

Sonarlint false positive NullPointer warning (S2259) when using ResponseEntity

For general restTemplate operation,as : ResponseEntity response = restTemplate.postForEntity(url, entity, ResponseVO.class); if (response.getBody() != null) { String url = response.getBody().getUrl(); I'm getting wrong sonar warning…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
1
vote
0 answers

Null guard / unwrapping in a single line in dart

Single line in Kotlin val prop = a?.prop ?: return Single line in Swift guard let prop = a?.prop else { return } Can this two line be single in dart ? var prop = a?.prop if (prop != null) { return }
TSR
  • 17,242
  • 27
  • 93
  • 197
1
vote
1 answer

Why is the use of [var x = new T()] resolving to [T?]?

I am using VS2022, .NET 6, C# 10, with the nullability context enabled project-wide. public static ModelEnumerationAttributeProperty FromPropertyInfo (PropertyInfo propertyInfo, object value) { var property =…
Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
1
vote
4 answers

Assignment after not null check

I expected that the type of a variable is promoted to a non-null type after a not-null check (like in the Dart language). val someMap = mapOf("a" to 0L) val a = someMap['a'] // a is of type Long? if (a != null) { val b = a // b is of type Long?…
1
vote
0 answers

EFCore 3.1 can not insert Null value to decimal? field and EF changed it to nvarchar

I'm using .net core 3.1. I have a table in MSSQL which has a nullable decimal column, and In code, I define it in its model file as (decimal?). In the repository when I want to insert my model to DB, I have this: //financialDb is my model that I…
1
vote
1 answer

Nullable type producing warnings since project has enabled nullable reference types

I only get the warnings after I enable nullable reference types, but the specific example is actually the good old Nullable type: var nullableItems = new List(); var actualNonNullValues = nullableItems.Where(x => x.HasValue) …
nvoigt
  • 75,013
  • 26
  • 93
  • 142
1
vote
3 answers

How to avoid null params with nullable reference types

Since C# 8.0 nullable reference types are possible. If they are enabled you have to append the ? to the reference type to make it nullable. My question now is how can I force a method parameter that uses the params keyword, to be…
Robert S.
  • 1,942
  • 16
  • 22
1
vote
2 answers

Jaxb generated sources with nullable fields

I have kotlin project where I'm using Jaxb generated src files from xsd. The problem with these generated sources is that they have nullable fields but IDEA does not know about it. It can lead to bugs in production. To fix it we can add @Nullable…
lalilulelo_1986
  • 526
  • 3
  • 7
  • 18
1
vote
1 answer

Nullable generic type that can be an int or string

I'm trying to create an interface that will add a column to a database entity which will be used the track the user making changes. public interface IAuditEntity { TKey? UpdatedBy { get; set; } } The interface will be used by different…
Sun
  • 4,458
  • 14
  • 66
  • 108
1
vote
1 answer

Kotlin: how to put two statements "apply" and "let" together in a nice way?

I'll stick to abstractions in code for simplicity. So I'm writing a function that takes some nullable color to set it only if it's not null. I'm using a Builder, the code looks something like this: private fun buildIcon(color: Color? = null) = …
1
vote
2 answers

Why is this Kotlin condition marked as always 'true'?

I have this bit of code to check if my mongoDB connection is still active: val isConnected: Boolean get() = if (instance!!.connection != null) { try { …
clem585
  • 53
  • 5
1
vote
1 answer

How to handle "Nullable value type may be null" (for TimeSpan) inside the sum() methode?

In my Asp.net core project, I need to check for null TimeSpan properties. This is my method: return result.Include(e => e.Episodes).AsEnumerable().Select(c => new ShowListCoursesViewModel() { CourseId = c.CourseId, …
1
vote
2 answers

C# ASP.NET MVC 2 basic routing

I'm quite new to ASP.NET and C# and I'm having some issues with my routing. Was hoping someone would be so kind to help me out. A user is supposed to give 3 parameters (string, bool, bool). So I have a small form on my index page: <% using…
Reinard
  • 3,624
  • 10
  • 43
  • 61
1
vote
0 answers

Does dart null safety variable need manual release?

I defined some nullable objects and used them elsewhere in State List? _data; int? _count; Do I need to release them manually? like this: @override void dispose() { _data?.clear(); // clear list _data = null; // blank manually …
SILENCE
  • 308
  • 2
  • 11
1
vote
2 answers

Is there a way to convince the compiler that a @NonNull variable is actually Nullable in Kotlin?

In Android, there is a android.location.LocationListener class, and the Android Operating System updates locations using the class as below: It says that Location is @NonNull, but in reality the OS does return null sometimes, which crashes the…
Jacques.S
  • 3,262
  • 2
  • 21
  • 27