Questions tagged [non-nullable]

232 questions
4
votes
2 answers

What are the differences between null analysis annotations packages?

The question Which @NotNull Java annotation should I use? is outdated and somewhat opinion based. Since then Java 8 came, along with newer IDEs. While Java 8 allows type annotations by integration of JSR 308, it does not come with any. From JSR 308…
user1803551
  • 12,965
  • 5
  • 47
  • 74
4
votes
3 answers

Android: NullPointerException despite @NonNull

I'm using annotations to ensure that parameter will be not null, assuming this would cause compiler check. public @Nullable ApplicationAccount accountForKey(@NonNull String key) { return accounts.get(key); } However, by running this code I…
4
votes
1 answer

How to use Objective-C __nonnull in a backwards-compatible way?

Xcode has recently added __nonnull, __nullable, etc. attributes. However, they're not supported by older versions of clang and other compilers. How can I use these attributes in a compatible way? I hoped something like this would work: #ifndef…
Kornel
  • 97,764
  • 37
  • 219
  • 309
4
votes
0 answers

"Value '' could not be converted." error when clearing ComboBox selection

I am trying to clear the selection in a ComboBox but get an error "Value '' could not be converted." The ComboBox's ItemSource is bound to a key-value pair list. The SelectedValue is the Key and the DisplayMemberPath is bound to the Value. If…
TechBang
  • 137
  • 1
  • 2
  • 6
4
votes
2 answers

Is it possible to define a "not Nullable" constraint in a C# generic method?

In C#, the Nullable type does not satisfy the where struct generic constraint (while AFAK this is techically a struct). This can be used to specify that the generic argument has to be a non-nullable value type : T DoSomething() where T :…
tigrou
  • 4,236
  • 5
  • 33
  • 59
4
votes
1 answer

Django 1.7: Makemigration: non-nullable field

I am trying to use django-orderedmodel (https://github.com/kirelagin/django-orderedmodel) in my project. Running makemigrations doesn't work: You are trying to add a non-nullable field 'order' to slide without a default; we can't do that (the…
cgwid
  • 43
  • 1
  • 3
4
votes
2 answers

Eclipse null type safety is wrong on return value

Eclipse seems to do wrong analisys , method test1 is ok, but method test2 give the error: Null type safety: The expression of type String needs unchecked conversion to conform to @NonNull public class TestCase { public Object o; @NonNull …
3
votes
2 answers

Is it possible in C# to write an implicit conversion operator for both nullable and non-nullable values?

I am trying to write an Alias class which enables me to: int n = new Count(1); That is, it encapsulates an int in this case as a Count, which gives some type safety and domain meaning, while it automatically converts back to the underlying…
Thomas Eyde
  • 3,820
  • 2
  • 25
  • 32
3
votes
2 answers

Can't assign to NonNullable even though I checked that value is defined

Trying to reach peak TypeScript performance I'm currently getting into some of the niche areas of the language, and there's something I don't get. With strict-null-checks and strict mode and that stuff enabled, I don't understand why this code gives…
NoBullsh1t
  • 483
  • 4
  • 14
3
votes
4 answers

The parameter 'id' can't have a value of 'null' because of its type, but the implicit default value is 'null'

I am following a Flutter tutorial that has such a following code, but code doesn't work on my computer, and I don't know how to fix it: import 'package:flutter/foundation.dart'; class CartItem { final String id; CartItem({ @required…
user11874694
3
votes
1 answer

EF Core conversion and non nullable type converted to a nullable primitive

I have a class MyClass that has a non nullable property Maybe MyMproperty. #nullable enable public class MyClass { public long Id { get; set; } public Maybe MyProperty { get; set; } } #nullable restore I declare and use en EF…
François
  • 3,164
  • 25
  • 58
3
votes
2 answers

C# Compiler's null state static analysis when validating objects

I have enabled Nullable check in my project and in a lot of places in the code I check input object and its properties and throw exception if something is wrong. But if everything is all right then I'm certain that input object is not null. Is there…
3
votes
1 answer

Are there any reasons not to always use the non-nullable reference types of C# 8.0?

Context C# 8.0 has this features of non-nullable reference types. string notNull = "Hello"; string? nullable = default; notNull = nullable!; // null forgiveness Question What reasons are there to not always enable non-nullability in the *.csproj…
Lernkurve
  • 20,203
  • 28
  • 86
  • 118
3
votes
1 answer

Whats wrong with non nullable objects?

I have been looking at DbC lately and Spec# which seem to have support for non nullable objects. Unfortunately Spec# seem to have been abandoned. Spec# seemed to have lots of nice language features built in so why was it abandoned? Would there be…
terjetyl
  • 9,497
  • 4
  • 54
  • 72
3
votes
1 answer

Are Objective-C function results nonnull by default?

In this thread on implementing a UITextInput delegate method, the poster says that when they run static analysis on their code, they get an error on this function: - (NSArray *)selectionRectsForRange:(UITextRange *)range { return nil; } The…
Duncan C
  • 128,072
  • 22
  • 173
  • 272