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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
23 views

Nullable functions dependency in PHP

I have a legacy application in which I modified a method from private function sendMail(mixed $from, mixed $to, string $subject, string $body, array $ccn = []): void to private function sendMail(...
Salvio's user avatar
  • 9
1 vote
0 answers
40 views

Is there a built-in function to query a type hint for optionality/"None-ability" in Python 3.10 or later?

Is there a function in the standard library to query whether the type hint for a field admits the None value? For example, it would return True for foo, bar, baz, and False for x, in class A below: ...
Ross Bencina's user avatar
  • 3,764
0 votes
0 answers
24 views

Missing C# Possible null reference assignment error in protobuf message

I have a custom message type which serves as a wrapper for byte in order to avoid casting in the application code and show the intended value range explicitly. I use that in a message declared as ...
Bartosz's user avatar
  • 4,286
0 votes
0 answers
20 views

Nullable Value Types as Members in a Struct: What are the Implications Memory-Wise? [duplicate]

I'm new to StackOverflow so sorry if anything about this post is weird or poorly formatted, giving it my best here, I'm also infamously bad with programming linguo so I might sound incredibly dumb as ...
Spring E. Thing's user avatar
1 vote
2 answers
57 views

How to tell VS that member is not null

I have a class that is like class Operation { private int? opA = null; private int? opB = null; private Func<int>? opFunc = null; public void SetOperandA(...
user137794's user avatar
  • 1,601
0 votes
1 answer
30 views

Why does `toString()` method on a null object in Dart not throw an exception?

I have the following code snippet in Dart: void main(List<String> args){ String? test1 = null; String test2 = test1.toString(); print(test1); print(test2); } I expected the second print() ...
Siavash TS's user avatar
0 votes
1 answer
55 views

Method that returns nullable that works for reference- as well as value types

I started like that: T? Foo<T>(T obj) //where T : struct { return Random.Shared.Next() < 100 ? (T?)null : (T?)obj; } which leads to this error: Cannot convert null to 'type' because it ...
codymanix's user avatar
  • 28.3k
0 votes
0 answers
15 views

Inference on platform types after calling a member of the platform type

Consider the following piece of code: val subDirectory = File("/path/to/some/dir") val imageFiles = subDirectory.listFiles() ?.filter { it.isFile && it.extension.equals("jpg&...
vatbub's user avatar
  • 2,550
0 votes
0 answers
76 views

How to convert the string value content to the generic `int?` (nullable int)?

Having a method with generic output type, I need to convert a string value (read inside the method) to the given type T that can also be nullable. The simplified method code looks like this: ...
pepr's user avatar
  • 19.9k
0 votes
3 answers
63 views

C# does not accept null for a `params object?[] values` parameter

I have a parameter defined like that: params object?[] values and I cannot send null in (i.e. I would like to have an array with one null inside). It does work without params. The error is: Cannot ...
Ilya Chernomordik's user avatar
2 votes
1 answer
72 views

Why doesn't LINQ SQL syntax respect nullability inference?

Consider these two methods: IEnumerable<T> WhereNotNull<T>(IEnumerable<T?> seq) => from item in seq select item; IEnumerable<T> WhereNotNull2<T>(IEnumerable<T?&...
NickL's user avatar
  • 1,871
0 votes
0 answers
29 views

C# Trying to access content "member variables" values within a object? (Nullable<object>) instance

Here is info about our technical development environment : • .NET 6 • C# 10 • Visual Studio 2022 Here is my code: public class TestEntity { public int TestMethod() { object? ...
crazyTech's user avatar
  • 1,347
0 votes
2 answers
54 views

How to resolve error regarding null value passed in Guid property?

I am trying to post JSON as which is supposed to work as a request body for a filter/search , so null value is allowed: { "Guid":"", "FirstName":"", ...
BlackCat's user avatar
  • 1,920
6 votes
2 answers
203 views

Why does C# attempt to convert int? to byte when using Math.Min?

I just discovered this interesting issue: int done = 50; int? total = 100; var perc = done * 100 / total; // No problem // Error: Argument 2: cannot convert from 'int?' to 'byte' // Argument 1 is ...
Luke Vo's user avatar
  • 17.2k
-1 votes
1 answer
84 views

Vector of 'nullable' HashMaps in rust

I am finding extremely difficult to deal with vectors of HashMaps in rust. I want to use vectors of HashMaps as an implementation of a sparse matrix container according to constraints that I, ...
Redirectk's user avatar
  • 138
4 votes
3 answers
80 views

KeyCollection as IEnumerable produces inconsistent LINQ behavior

The following code prints "false" IEnumerable<string> x = new List<string>(); Console.WriteLine(x.Contains(null)); But this code throws an ArgumentNullException: IEnumerable<...
chanban's user avatar
  • 458
0 votes
2 answers
51 views

C# nullable DateOnly Linq how to?

I have a class eg. Range which has two DateOnly property, begin and end. The end property is optional so it's nullable. (open ended range) eg. public class Range { public DateOnly begin { get; set; } ...
L. Kvri's user avatar
  • 1,432
0 votes
2 answers
137 views

C# .NET 7, I got Nullable Object must have a value when trying to query data from DBContext

By using .NET 7, my code as below var query = from c in dbContext.Customers from o in dbContext.Orders.Select(o => new { Id = o.Id, Number = o.Number }).Where(o => o....
Dan Van's user avatar
  • 51
3 votes
1 answer
70 views

Unexpected behavior when switching to BAVET for entity with nullable planning variable

OptaPlanner 8.36.0.Final When using ConstraintStreamImplType.DROOLS the following constraint behaves as expected: return constraintFactory .forEach(Ewe.class) .groupBy(ConstraintCollectors....
Steven's user avatar
  • 33
0 votes
1 answer
272 views

Sonar Cube throws bug saying as "is null on at least one execution path."

c# code if (numlist.Any()) { numlist.FirstOrDefault(c => c.Number == request.Number).ValCount = request.Count; } Sonar Cube throws bug message saying as 'numlist.FirstOrDefault(c => c....
Developer's user avatar
3 votes
2 answers
91 views

How to avoid CS8618 warning occur at the point of declaration?

Assuming the following C# code (and assuming nullable is on): class Foo { public string Bar; } var foo = new Foo { Bar = "some value" }; How can I avoid a CS8618 warning declaring Bar ...
Dylan Nicholson's user avatar
0 votes
0 answers
22 views

React-native Update form Data

React native I have update the form data using API. I can send the textinput values to store. But they only send null values. In postman the data store correctly react-native contains only error.How ...
Raj kumar's user avatar
5 votes
3 answers
206 views

My legacy code on net core 3.1 is throwing exception when moving to .NET 7 with message "Nullable object must have a value"

My code is below, working fine in .NET Core 3.1: // dto is search criteria passing from outside var query = from p in dbContext.Products.Where(p => dto.Ids.Contains(p.Id)) from c in ...
Dan Van's user avatar
  • 51
0 votes
0 answers
46 views

Nest Typeorm Float type and empty string from form

I have a field that is definend as nullable float. However, from the form I'm expecting an input that is a number or an empty string (or something else). Now, typeorm/nest is handing over the empty ...
RK234's user avatar
  • 11
2 votes
1 answer
85 views

Swift: `["one": nil] as [String: Any]` works, why?

func logEvent(events: [String: Any]) { print(events); } let eventProperties: [String: Any?] = [ "one": nil, "two": "2" ] logEvent(events: eventProperties as [...
TpoM6oH's user avatar
  • 8,335
1 vote
1 answer
45 views

Type conversion error CS0029 when filtering list of nullable enums using LINQ

This code compiles just fine: public record Foo ( double X ); private static void Test() { IImmutableList<Foo?> myList = ImmutableList<Foo?>.Empty.Add(new Foo(42)).Add(null); ...
Joerg's user avatar
  • 730
0 votes
1 answer
80 views

blazor http generic client what is proper way to handle nulable type like this?

I build some blazor app and i want to have HttpGet like person? x = await _httpClient.Get<person?>("url"); So from api if i return person then i want x to be it value, if from api i ...
d00lar's user avatar
  • 795
0 votes
1 answer
58 views

How to interpret null-coalescing operators in c#

I have been given some code using nullable types, which are new to me (I learnt C# many years ago, in its infancy, and haven't kept up, sorry!) The code I am trying to understand is public readonly ...
quilkin's user avatar
  • 864
2 votes
3 answers
253 views

EF Core 7 Linq with a 'Contains" generates an SQL with an extra 'or is not null'

I recently updated EF Core 6 to 7, and now a query has become a lot slower than before without any changes. It looks like EF Core translated the LINQ query to a different SQL query. Versions: .NET: 7 ...
J Flex's user avatar
  • 292
0 votes
2 answers
93 views

Null check operator used on a null value - state management with provider and getter error

I am building an Instagram clone with Flutter, and on the upload page, I'm trying to upload the image through a Provider and a Getter; code here: final User user = Provider.of<UserProvider>(...
Woke  Vibes Hollys's user avatar
0 votes
1 answer
69 views

How to assign a new variable to the "List<Class>" members in Flutter?

I have a code like following: var book = Provider.of<Book>(context, listen: false); ElevatedButton( onPressed: () async { FilePickerResult? result = await FilePicker.platform ....
best_of_man's user avatar
1 vote
1 answer
45 views

How to mark a type as not null?

I want a generic method (or class) to behave something like this: val instanceS = MyCoolClass<String?>() instanceS.someMethod("some not null string") //compiles instanceS.someMethod(...
caeus's user avatar
  • 2,974
1 vote
2 answers
66 views

Why do I get this error: _CastError (Null check operator used on a null value)

I have a column like this: Column(children: [ product.videos![product.videoIndex].videoUrl != null && product.videos![product.videoIndex].videoUrl != "" ? ...
best_of_man's user avatar
0 votes
2 answers
96 views

flutter_platform_widgets preventing build

I was working on my Flutter application and was not having any problems. When I was finished, I ran flutter upgrade as a new version was available. my first time attempting to run since the upgrade, ...
Coder1703's user avatar
2 votes
1 answer
100 views

Dereference of a possibly null reference in child class

Is it possible to tell the compiler that I know a method will return an object with a non-null property, even though that property is marked as nullable? For example: var seat = GetOccupiedSeat(); ...
devklick's user avatar
  • 1,843
0 votes
2 answers
46 views

Eliminate redundant null checks: method decomposition and nullability in c#

Everything about nullability is great in c#. But how should we deal with it when decomposing code? Imagine that we have one big method. It receives some object, check important fields for null and ...
stone-w4tch3r's user avatar
1 vote
1 answer
110 views

Operator call corresponds to a dot-qualified call 'n.compareTo(3)' which is not allowed on a nullable receiver 'n'

I have the following code: val n = readln().toIntOrNull() if (n > 3) { println(n) } I am receiving above subject error: Operator call corresponds to a dot-qualified call 'n.compareTo(3)' ...
Jaguar's user avatar
  • 15
0 votes
1 answer
107 views

How can I tell C# that non-nullable value can be null (opposite to null-forgiving operator)

I use Entity Framework Core 7. When I declare an entity that is guaranteed to have a reference property, I declare it as non-nullable: public class Employee { public Employer Employer { get; set; }...
THX-1138's user avatar
  • 21.2k
0 votes
0 answers
11 views

System.Linq.Expression: Parse Nullable<DateTime>

I want to make a generic filter so I'm creating System.Linq.Expression Lambda function. The next piece of code works with DateTime, but not with DateTime?. var parametro = Expression.Parameter(typeof(...
Max Bertoli's user avatar
0 votes
0 answers
31 views

Generic Nullability In Expression

I would like to know how should I change KO signature to allow generic nullability as OK does: public class X {} public static class G { public static void OK<T>(T? p) where T: class {} ...
dani herrera's user avatar
0 votes
0 answers
56 views

Nullable generic parameter C# [duplicate]

Working with <Nullable>enable</Nullable>, how can I fix KO method to allow expression1 as parameter? public class X { public DateTime? dummy {get; } } public static class G { // ...
dani herrera's user avatar
0 votes
0 answers
99 views

Make all fields in Java Immutable Nullable

@Immutable @Modifiable public interface Record { String id(); String fName(); String lName(); String mName(); } All the fields in Record can be Nullable. One way for me to make ...
Adi's user avatar
  • 367
0 votes
3 answers
46 views

Value is false but still giving error null check operator

You understand better when see the code and error. I have a StatelessWidget names StateWidget like this: class StateWidget extends StatelessWidget { const StateWidget({ super.key, required ...
Mehmet's user avatar
  • 53
-1 votes
2 answers
125 views

With PropertyInfo.PropertyType, how to determine if property is a nullable bool

I'm trying to set default property values for certain classes. Because the classes are generated automatically, I don't want to have to set them in the individual classes, so I created an extension ...
E. A. Bagby's user avatar
2 votes
2 answers
335 views

Mapster - Map non-nullable type to nullable type

I am using mapster to map between entities and DTOs. I have noticed it will not map a Guid? to a Guid (or vice-versa) even if I add it explicitely to a mapping register like such : public sealed ...
Martin's user avatar
  • 1,947
0 votes
1 answer
117 views

The argument type 'String?' can't be assigned to the parameter type 'String' in flutter

'The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't' pleas can any one help me with this error. i faced this error will ...
Ahmed Maged's user avatar
0 votes
1 answer
492 views

Optional.ofNullable() on List

I need an assistance on one of the optional concepts of java 8+. I have been seeing developers using Optional.ofNullable on list object which is incorrect and I am not sure how its been working ...
Sachi97's user avatar
  • 19
0 votes
0 answers
13 views

C# Suppress nullable after custom thrower method, like ArgumentNullException.ThrowIfNull [duplicate]

I'm trying to create similar functionality to that of the ArgumentNullException.ThrowIfNull method, in that the compiler should know that when the input argument is null, any code executed after the ...
devklick's user avatar
  • 1,843
0 votes
1 answer
64 views

Guarantee to return a non-empty tuple (non null fields) in C# [closed]

I wrote this code: var (left, right) = A.FooWith(B); where left, right, A and B are all Ts: public class T { // ... public (T left, T right) FooWith(T other) { T left = new (GetInfoFrom(this, ...
WaterFox's user avatar
  • 809
4 votes
1 answer
101 views

C# Nullable issues with implicitly-typed local variables

I already know from this thread that implicitly declared reference types are nullable in .NET 7 even when Nullable set to "Enabled", I even know why. I am not asking why. I am asking ...
Joe's user avatar
  • 5,026

1
2 3 4 5
48