Skip to content

Commit

Permalink
[Java.Interop] Fix C# warnings (#652)
Browse files Browse the repository at this point in the history
Fixes 43 Nullable Reference Type warnings

Fixes CS0168 warning:

	The variable 'e' is declared but never used.

Fixes 6 CA1307 warnings introduced by targeting `netcoreapp3.1`:

	The behavior of 'string.IndexOf(char)' could vary based on the current user's locale settings.
  • Loading branch information
jpobst authored and jonpryor committed Jun 11, 2020
1 parent fb6d5f9 commit abfade5
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 93 deletions.
10 changes: 5 additions & 5 deletions src/Java.Interop/Java.Interop/JavaArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,31 @@ bool ICollection<T>.Remove (T item)
throw new NotSupportedException ();
}

bool IList.Contains (object value)
bool IList.Contains (object? value)
{
if (value is T)
return Contains ((T) value);
return false;
}

int IList.IndexOf (object value)
int IList.IndexOf (object? value)
{
if (value is T)
return IndexOf ((T) value);
return -1;
}

int IList.Add (object value)
int IList.Add (object? value)
{
throw new NotSupportedException ();
}

void IList.Insert (int index, object value)
void IList.Insert (int index, object? value)
{
throw new NotSupportedException ();
}

void IList.Remove (object value)
void IList.Remove (object? value)
{
throw new NotSupportedException ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop/JavaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected virtual void Dispose (bool disposing)
}
}

public override bool Equals (object obj)
public override bool Equals (object? obj)
{
JniPeerMembers.AssertSelf (this);

Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop/JavaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected virtual void Dispose (bool disposing)
{
}

public override bool Equals (object obj)
public override bool Equals (object? obj)
{
JniPeerMembers.AssertSelf (this);

Expand Down
33 changes: 17 additions & 16 deletions src/Java.Interop/Java.Interop/JavaPrimitiveArrays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Java.Interop.Expressions;
using System.Linq.Expressions;
using System.Diagnostics.CodeAnalysis;

namespace Java.Interop {

Expand Down Expand Up @@ -246,7 +247,7 @@ public override IList<Boolean> CreateGenericValue (ref JniObjectReference refere
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaBooleanArray (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Boolean> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Boolean> value, ParameterAttributes synchronize)
{
return JavaArray<Boolean>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -257,7 +258,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Boolean> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Boolean> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Boolean>.DestroyArgumentState<JavaBooleanArray> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -422,7 +423,7 @@ public override IList<SByte> CreateGenericValue (ref JniObjectReference referenc
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaSByteArray (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<SByte> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<SByte> value, ParameterAttributes synchronize)
{
return JavaArray<SByte>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -433,7 +434,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<SByte> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<SByte> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<SByte>.DestroyArgumentState<JavaSByteArray> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -598,7 +599,7 @@ public override IList<Char> CreateGenericValue (ref JniObjectReference reference
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaCharArray (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Char> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Char> value, ParameterAttributes synchronize)
{
return JavaArray<Char>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -609,7 +610,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Char> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Char> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Char>.DestroyArgumentState<JavaCharArray> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -774,7 +775,7 @@ public override IList<Int16> CreateGenericValue (ref JniObjectReference referenc
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt16Array (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int16> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Int16> value, ParameterAttributes synchronize)
{
return JavaArray<Int16>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -785,7 +786,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Int16> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Int16> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Int16>.DestroyArgumentState<JavaInt16Array> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -950,7 +951,7 @@ public override IList<Int32> CreateGenericValue (ref JniObjectReference referenc
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt32Array (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int32> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Int32> value, ParameterAttributes synchronize)
{
return JavaArray<Int32>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -961,7 +962,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Int32> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Int32> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Int32>.DestroyArgumentState<JavaInt32Array> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -1126,7 +1127,7 @@ public override IList<Int64> CreateGenericValue (ref JniObjectReference referenc
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt64Array (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int64> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Int64> value, ParameterAttributes synchronize)
{
return JavaArray<Int64>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -1137,7 +1138,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Int64> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Int64> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Int64>.DestroyArgumentState<JavaInt64Array> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -1302,7 +1303,7 @@ public override IList<Single> CreateGenericValue (ref JniObjectReference referen
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaSingleArray (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Single> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Single> value, ParameterAttributes synchronize)
{
return JavaArray<Single>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -1313,7 +1314,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Single> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Single> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Single>.DestroyArgumentState<JavaSingleArray> (value, ref state, synchronize);
}
Expand Down Expand Up @@ -1478,7 +1479,7 @@ public override IList<Double> CreateGenericValue (ref JniObjectReference referen
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaDoubleArray (ref h, o));
}

public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Double> value, ParameterAttributes synchronize)
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull] IList<Double> value, ParameterAttributes synchronize)
{
return JavaArray<Double>.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
Expand All @@ -1489,7 +1490,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}

public override void DestroyGenericArgumentState (IList<Double> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
public override void DestroyGenericArgumentState ([AllowNull] IList<Double> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray<Double>.DestroyArgumentState<JavaDoubleArray> (value, ref state, synchronize);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Java.Interop/Java.Interop/JavaProxyObject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -51,7 +51,7 @@ public override bool Equals (object? obj)

public bool Equals (JavaProxyObject? other) => object.Equals (Value, other?.Value);

public override string ToString ()
public override string? ToString ()
{
return Value.ToString ();
}
Expand All @@ -63,8 +63,7 @@ public override string ToString ()
return null;

lock (CachedValues) {
JavaProxyObject proxy;
if (CachedValues.TryGetValue (value, out proxy))
if (CachedValues.TryGetValue (value, out var proxy))
return proxy;
proxy = new JavaProxyObject (value);
CachedValues.Add (value, proxy);
Expand Down
Loading

0 comments on commit abfade5

Please sign in to comment.