2,505 questions
0
votes
1
answer
51
views
"Type argument is not within its bounds: must be subtype of 'Any'" in Kotlin application after upgrade to Spring Boot 4.0.0
After upgrading my Kotlin application from Spring Boot 3.5.8 to Spring Boot 4.0.0,
I get a lot of compiler errors
Type argument is not within its bounds: must be subtype of 'Any'.
How is it possible ...
Advice
0
votes
1
replies
49
views
In which scenario the UsersRequestBuilder.get() from Microsoft Graph SDK will return null?
I am using the com.microsoft.graph.serviceclient.GraphServiceClient class to retrieve users:
UserCollectionResponse userCollectionResponse = graphClient.users().get(conf -> {
conf....
2
votes
2
answers
126
views
C# Pass null to Generic Method Receiving Nullable Type [duplicate]
The following code generates CS1503 with the message:
error CS1503: Argument 1: cannot convert from '<null>' to 'T?'
public class MyClass<T> where T : notnull
{
// This is the only ...
5
votes
1
answer
140
views
Accessing JSpecify Nullable annotation via reflection
I'm trying to run the following code with Java 25
package test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Field;
import org.jspecify.annotations.Nullable;
...
1
vote
1
answer
262
views
'Member may be null' even though it is set in base constructor
Suppose in C# I have one class that inherits from another like this:
internal class TestImplementation : TestBase
{
[SetsRequiredMembers]
public TestImplementation(List<string> param) : ...
0
votes
0
answers
34
views
Annotation to tell null-checking a property is not null?
Consider this code (C# 12/.NET 8):
class Content
{
public string Value { get; set; }
}
class Something
{
public bool IsOK { get; set; }
public Content? TheContent { get; set; }
}
...
-3
votes
1
answer
103
views
How can I pass a reference to an internal class upon construction of a public-facing subclass without violating nullabe safety?
I'm not super experienced with C#, and this is a bit of a puzzle. Consider the following code:
#nullable enable
using System.Collections.Generic;
// Biology.dll
public abstract class Animal
{
...
2
votes
1
answer
170
views
AnyNull extension method - is there a way to assert nullability?
So I've got a little method that looks like:
public static bool AnyNull(params object?[] args)
{
if (args.Any(a => IsNull(a)))
{
return true;
}
return false;
}
private ...
2
votes
3
answers
271
views
Why does List.copyOf(...) use a redundant array creation?
The method java.util.List#copyOf in Java 24 calls another method java.util.ImmutableCollections#listCopy which has the following body:
@SuppressWarnings("unchecked")
static <E> ...
1
vote
1
answer
118
views
NotNullIfNotNull, but using the return value instead of a parameter
I have a function that returns a nullable result and has an out parameter that is also nullable:
public Result? GetResult(out Parameter? parameter)
{
Result? result = //...get the result somehow
...
1
vote
2
answers
103
views
Nullable property in generic interface [duplicate]
I've read several of the other questions on the topic of nullable types in generics and I still don't understand why MinMaxBase<T> and MyIntDecl compile and YourIntDecl doesn't.
The compiler ...
1
vote
2
answers
134
views
Is there a way to tell the compiler in C# that nullable collection inside object was already checked for null earlier in the call stack?
I have this one specific case, where I have a model for an entity in our project, and that model has a collection inside it.
That collection is nullable, like so:
public class Model {
public List<...
0
votes
1
answer
104
views
Reference to value in nested nullable structs
I am guessing the answer will eventually be "no, you can't do that", but trying to figure out how to do a thing in C#.
I am wondering on a bit of glue code between two pieces that I do not ...
0
votes
2
answers
110
views
How to distinguish a generic default parameter value from a user-provided one? [duplicate]
I am working on a program that can use different cryptographical ciphers, though I don't think the actual application is incorrect. The
entire codebase is here (a bit of an older version without the ...
0
votes
1
answer
85
views
Nullable T parameter
I have an object with the following inheritance:
[ProtoContract]
public class Country : CountryCommon<Country, ConstructDB.Country>
{
Which inherits:
public abstract class CountryCommon<T, ...
2
votes
0
answers
84
views
OpenAPI generator fails create nullable array items
I have such a component in swagger.json (OpenAPI version: "3.0.1")
"ids": {
"type": "array",
"items": {
"type": "string",
...
0
votes
0
answers
50
views
Why is PropertyInfo returning this weird type name (nullable boolean within a class)? [duplicate]
I ran the following code:
String s = String.Empty;
bool abool = false;
bool? nbool = false;
BoolsClass bc = new BoolsClass();
bc.classbool = false;
bc.classnbool = false;
s += $"The type of ...
3
votes
2
answers
132
views
Is it possible to get underlying type of Nullable<T> if default value is set to null
I'm trying to parse an XML file which has same tags with varying number of attributes (some attributes may not be present) to C# class.
If an attribute isn't present, its value should be set to null, ...
0
votes
0
answers
41
views
C# Make Null-filled array be valid for any generic type [duplicate]
I have this code, which also compiles and works:
public partial class MeasurementInfoLabel : Label
{
/// <summary>
/// The two points clicked.
/// </summary>
public PointF?[...
0
votes
1
answer
40
views
Disambiguation best practice for generic type T? based on reference vs value
I have a large .NET 9 code base maintained by a team. It doesn't all have null-checking enabled as we have migrated it up from .NET Core originally, but we are introducing it (one assembly at a time ...
2
votes
2
answers
81
views
Generate a script out of nullable column in SQL table [duplicate]
Following is my query:
SELECT 'INSERT INTO MyTable (
CancellationReason
)
VALUES (
''' + rc.CancelReason + '''
)'
FROM AnotherTable a
I get below result:
Since the column a.CancelReason is ...
5
votes
2
answers
116
views
Can I null-check multiple variables in one pass without triggering nullability warnings?
I am attempting to validate multiple config parameters, ideally reporting all issues in a single pass. This takes a form similar to:
var isValid = true;
if (arg1 == null)
{
// logger.LogError...
...
0
votes
1
answer
97
views
IntelliJ - ignore "Not-null fields must be initialized" for injected fields
IntelliJ keeps telling me i have to initialize my injected fields. I know a workaround would be to create a ctor and annotate it with @Inject but i dont want to change all of my classes. So is there a ...
0
votes
1
answer
93
views
EF Core 2.1 to EF Core 8/.NET 8 migration: Why does this EF Core InMemory query generate a 'Nullable object must have a value' error
After upgrading my .NET 5.0 project to .NET 8.0, the LINQ query now generates an exception
System.InvalidOperationException: Nullable object must have a value
The code below executes successfully in ...
1
vote
1
answer
91
views
How to correctly write a `bool TrySomething(out)` implementation for both reference and value types?
Considering the following class:
public class Property
{
public string StringValue { get; private set; }
private Property(string value)
{
this.StringValue = value;
}
}
I am ...
0
votes
1
answer
56
views
Best practice on handling null API responses from AWS API calls
Lets say I invoke AWS APIs in my java/kotlin code. Example on getHostedZone route53 API below.
Should I check if response == null first or is response guaranteed to be non null? Is null pointer check ...
-1
votes
1
answer
80
views
Checking if nullable type object is null (passes check, when it shouldn't) [duplicate]
So I created a nullable class, say called Unit, the instance is created:
unit??=new Unit(pars)
I check if it's null:
Debug.Log("check" + unit==null);
returns False. I test if it's null:
if ...
1
vote
1
answer
116
views
How can I check if a generic enum has value?
In my C# application, I have an abstract class that is a wrapper around UnitsNet library to group closely related properties (such as a numeric value and unit for that value that user has chosen), to ...
1
vote
3
answers
208
views
Nullable types and early stopping issue
In C# when having nullable objects such as Decimal?, Int?, etc. While doing null checks, but with early stopping.
The compiler does not track the nullability of such object (prevMaxSpeed in this case) ...
1
vote
0
answers
39
views
Npgsql 4.1.14: call stored procedure with nullable types
I have the following PostgreSQL "function1"
function1(par1 Enum_1),
function1(par1 integer),
...
function1(par1 text)
In Npgsql V 3.2.7, the parameters could be created together with the ...
0
votes
1
answer
92
views
Shorthand nullable variable assignment in C# [duplicate]
In my C# WPF project I am trying to assign a value to nullable short with the shorthand function:
short? var = (textbox.Text.Length > 0) ? short.Parse(textbox.Text) : null;
Visualstudio does not ...
1
vote
1
answer
91
views
C# 8 - using both nullable and non-nullable version of the type in the generic
I need to use two versions of base type in the same generic: nullable and non-nullable.
Like int? and int, Guid? and Guid, DateOnly? and DateOnly and so on.
Nullable type should be at the class ...
0
votes
0
answers
56
views
How to store generic value-types as nullable
Take the following code (or check it out online):
public class Program
{
public static void Main()
{
var foo = new MyNullable<int>();
var bar = new MyNullable<string&...
1
vote
1
answer
78
views
Is it possible to return nullable T for generic method with incoming T that can be class or struct?
Dummy code:
// TSource1 elementObj can be struct or can be class object and never can be nullable struct or null (because method inner code will create Exceptions in that case)
public static TSource1? ...
1
vote
1
answer
59
views
C# help compiler to infer nullability
Conside this simple class in C# (nullability feature enabled):
public class Error
{
public string Message = "...";
public static implicit operator bool(Error? err) => err is not ...
1
vote
1
answer
57
views
Nullable diagnostic CS8621 raised without reason
I have a razor component in a separate project that defines a search parameter like this:
[Parameter, EditorRequired]
public Func<string, Task<IEnumerable<T>>> Search { get; set; } = ...
-1
votes
1
answer
101
views
How can I tag a value as not expected to be null?
I have a function that's correctly specified as returning a potentially-null object. My code calls that function but in a way where it isn't going to return a null.
MyClass? MyFunction(string x);
/* .....
-1
votes
1
answer
26
views
I want to fetch the Rolename on the behalf of User Id and this join code Rolname is going nulll
public IActionResult Login( UserDto dto)
{
try
{
var roleName = (from r in _context.Roles
join u in _context.Users on r.UserId equals u.UserId
...
5
votes
3
answers
148
views
C#: Nullable Generic Types, unexpected behavior [duplicate]
I was wondering why this was the case, as it went against what I would have expected. This has to do with how Generic Nullable types are interpreted in C#.
public static int? MyFunction(){
...
2
votes
1
answer
109
views
Clickhouse create from select set the value to 0 when given null for a nullable(Int8) column
I am trying to create a table in ClickHouse with the following SQL
CREATE TABLE stage.test_int_null (
is_active Nullable(Int8),
name String
) ENGINE = MergeTree()
ORDER BY (tuple()) AS
select ...
1
vote
0
answers
32
views
Avoid nullability warning/error when enabling CS8602
Consider the following helper method which comes from a legacy codebase
public static class ListHelper
{
public static bool HasAny<T>(this IReadOnlyCollection<T>? list)
{
...
1
vote
3
answers
207
views
How to cause tearing on Nullable<long>?
If I run the below code in x86 (32-bit) mode (.NET Framework 4.7.2 on recent Windows 11 machine) then, as expected, it writes to the console (proving that the data read out is not one of the two ...
0
votes
1
answer
114
views
How to do null safe calls (?. operator) with Arrays? [duplicate]
I am trying to get items from a nullable array using a safe call (?. operator).
data class myObject(val i: Int)
var arr: Array<myObject>? = arrayOf(myObject(123),myObject(456))
// var arr: ...
1
vote
1
answer
105
views
C# - How to compare multiple nullable values to check if those that have value are equal?
What is the easiest way to check multiple nullable values, to know if those that are not null are equal?
double? a = null
double? b = 2;
double? c = 3.5;
should return false
double? a = 2.5
double? b ...
0
votes
1
answer
88
views
Construct a copy of an object with nullable fields nulled if they haven't been changed since construction [closed]
I have Java classes with some nullable members, which get constructed from JSON objects with some optional keys. After construction, I will modify the objects, populating some previously-null members, ...
0
votes
0
answers
94
views
Why a non-null warning on a nullable property?
Here's my code that declares & sets ReturnUrl.
public class ExPageBase : ExComponentBase
{
[Parameter]
[SupplyParameterFromQuery(Name = "returnUrl")]
public string? ReturnUrl ...
1
vote
1
answer
63
views
C# nullability analysis - inconsistent tooltip
I've found a strange inconsistency between the nullability of a variable in the hover-over tooltip in Visual Studio / sharplab.io and the compiler's handling of the variable re nullability.
I wanted ...
0
votes
1
answer
91
views
What is the common way to handle CS8602 in a WPF RelayCommand?
If a nullable property gets used in the Execute part of a RelayCommand, and that property is already checked against null in the CanExecute method, what is the proper way to handle the CS8602: ...
0
votes
1
answer
80
views
Possible error in C# compiler warning output for nullability checking
Type type = typeof(Program);
type = type.BaseType; // [CS8600] Converting null literal or possible null value to non-nullable type.
do
{
type = type.BaseType; // [CS8602] Dereference of a ...
1
vote
1
answer
71
views
How to set pandas.DataFrame cell to null without FutureWarning
I would like to set some cells to null based on a condition. For example:
import pandas as pd # version is 2.2.2
df = pd.DataFrame({'x' : [1, 2, 2, 1, 1, 2]})
df["b"]=False
df.loc[df["x&...