Questions tagged [non-nullable]

232 questions
1
vote
1 answer

C# Make list of different structs and get them as nonnullable

I need to make container class for different structs(which inherit after same interface) but the thing is container needs to have GetStructAt(int index) method which returns non-nullable type. Example: public interface IExampleInterface {} public…
user6601263
1
vote
1 answer

EF6: migration generates nullable string despite IsRequired

I'm trying to generate a migration for a new Entity class that has a string field, called "Name". That string field should not be nullable. I'm aware that "nullable" and "non-empty" are two different issues (see EF 6 IsRequired() allowing empty…
jeancallisti
  • 1,046
  • 1
  • 11
  • 21
1
vote
1 answer

How to deal with nullable variables that are not null?

Consider this piece of code: var foo: Foo? = null if (foo != null) { foo!!.bar() } If I omit the two !! I get this error: Smart cast to 'Foo' is impossible, because 'foo' is a mutable property that could have been changed by this time This…
user1785730
  • 3,150
  • 4
  • 27
  • 50
1
vote
1 answer

Allow !! when it is certain it will not throw an NPE

I'm looking at a pull request, which contains !! - the not-null assertion operator. Should it be approved? The nullable value itself will indeed never be null. I can't think of a better argument than 'It feels wrong' private val hasFinishedSubject =…
Michiel
  • 767
  • 4
  • 19
1
vote
1 answer

Strictifying nullable fields for validation

I'm trying to get the compiler to help me with validation of payloads received over the network. So what I want to do is take a JSON payload over the wire and make sure the compiler complains if all the fields are not set. I know the way to do this…
David K.
  • 6,153
  • 10
  • 47
  • 78
1
vote
2 answers

Remove default value for non nullable properties when using EditFor [asp.net mvc 3]

How can I remove the default value that is added by default to the textboxes of non nullable properties when using the EditFor helper? I don't want that behavior EDIT Sorry I didn't give enough information. For example if you use Html.EditorFor with…
ryudice
  • 36,476
  • 32
  • 115
  • 163
1
vote
1 answer

Bool and Nullable Bool Usage Concerns in T-SQL/MS SQL

My team has a DB table, which is shared across multiple applications. The table has one primary key INT column and most of the columns are nullable boolean using for flags and configuration. Note that not all columns are being used in all…
frostshoxx
  • 538
  • 1
  • 7
  • 24
1
vote
0 answers

Non annotated methos as nullable by default

Is it possible to configure the IntelliJ or maybe the NullAway to consider non annotated method as Nullable by default? e.g. The following method: context.getResources().getString(R.string.app_name); The getResources is not annotated as nullable or…
ademar111190
  • 14,215
  • 14
  • 85
  • 114
1
vote
1 answer

@NonNull annotations on definitions- java 8

How to use @NonNull annotations on List items. let consider, if i want to force A non-null list of Strings This is how we can declare that : @NonNull List what if we want to force, A list of non-null Strings. How we can do that ?
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104
1
vote
1 answer

Can't recognize _Nonnull when building adb with g++

I am trying to build adb from the AOSP android 7.1.2 source code and compiling it with g++ (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609, by slowly adding includes and libraries based on the Android.mk and fixing the compiler complaints as I go. So…
user3325563
  • 187
  • 2
  • 12
1
vote
3 answers

How to convert an int array to a nullable int array?

Let's say I have an array containing x members and I want to create another array with the same Length (x) and the same integer values: int[] arr = new int[x]; int?[] nullable_arr = arr; And I can't do this: int?[] arr = new int[x]; Is there an…
SuperMinefudge
  • 301
  • 3
  • 11
1
vote
1 answer

How to get rid of "Null type safety" warning in eclipse neon for TreeMap

How to get rid of the warning in this example code. I use Eclipse Neon with Java 1.8 and org.eclipse.jdt.annotation_2.1.0 import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import…
Torge
  • 2,174
  • 1
  • 23
  • 33
1
vote
1 answer

Exactly how to use nonnull in certain cases in Objective C

I have read many posts about nullability but I can't for the life of me make my warnings go away. Here are a couple of examples: playPause = @[[UIImage imageNamed:@"Play"], [UIImage imageNamed: @"Pause"]]; [imagePropertiesFileHandle…
1
vote
2 answers

Cannot convert non-nullable type conversion problems vb.net to c#

I have copied a piece of legacy code written in VB.Net which when converted to C# has produced the following: /// ///Test whether SSAC should be serialized /// public virtual bool ShouldSerializeSSAC() { if…
Jay
  • 3,012
  • 14
  • 48
  • 99
1
vote
1 answer

Getting 'mismatching null constraints' error when implementing Map.entrySet (Java8, Eclipse)

I get the error... The return type is incompatible with 'Set>' returned from Map.entrySet() (mismatching null constraints) ...when implementing a Map and overriding Map.entrySet like this: package org.abego.util; import…
Udo Borkowski
  • 311
  • 1
  • 9