Skip to content

Enable NRT for Java.Interop.dll #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8752e63
Add #nullable for IJavaPeerable, JniEnvironment
jonpryor Nov 19, 2019
9d0994e
Add #nullable for more types
jonpryor Nov 19, 2019
583ad0d
Add #nullable for JavaProxyObject, JavaProxyThrowable
jonpryor Nov 19, 2019
80e490e
Add #nullable for JniArgumentValue
jonpryor Nov 19, 2019
b900b26
Add #nullable for JniBuiltinMarshalers
jonpryor Nov 19, 2019
56e5f64
Add #nullable for JniMethodInfo
jonpryor Nov 19, 2019
335ea70
Add #nullable for JniNativeMethodRegistration
jonpryor Nov 19, 2019
da4d2f1
Add #nullable for JniNativeMethodRegistrationArguments
jonpryor Nov 19, 2019
3006477
Add #nullable for JniObjectReference*
jonpryor Nov 19, 2019
607a6de
Add #nullable for JniRuntime.
jonpryor Nov 19, 2019
82567a2
Add #nullable for JniRuntime
jonpryor Nov 19, 2019
70a39c9
Add #nullable for JniSystem.
jonpryor Nov 19, 2019
9d3c875
Add #nullable for JniTransition
jonpryor Nov 19, 2019
26d3721
Add #nullable for JniType
jonpryor Nov 19, 2019
d18d533
Add #nullable for JniTypeSignature
jonpryor Nov 19, 2019
4358bb4
Add #nullable for JniTypeSignatureAttribute
jonpryor Nov 19, 2019
4a79f5f
Add #nullable for ManagedPeer
jonpryor Nov 19, 2019
3854bd3
Add #nullable for JniValueMarshalerAttribute
jonpryor Nov 19, 2019
8bcab04
Add #nullable for JniBuiltinMarshalers
jonpryor Nov 19, 2019
7841be9
Add #nullable for JniReleaseArrayElementsMode
jonpryor Nov 19, 2019
df2c08f
Add #nullable for JniStringValueMarshaler
jonpryor Nov 20, 2019
be62f33
Add #nullable for JniPeerMembers
jonpryor Nov 20, 2019
28a6d37
Review nullability on some JavaArray methods
jonpryor Nov 20, 2019
0b8e365
Set `$(Nullable)`=enable in Java.Interop.csproj
jonpryor Nov 20, 2019
bdd75c7
Bump .NET Core to 3.1.x to support NRT.
jpobst Jan 7, 2020
b6346db
Need a newer boots to support .Net Core 3.1.
jpobst Jan 7, 2020
2629ac1
Java.Interop.dll has to remain netstandard2.0 so our other assemblies…
jpobst Jan 7, 2020
935b332
Fix or suppress analyzer issues.
jpobst Jan 7, 2020
c9d30e4
IDisposable suppression.
jpobst Jan 7, 2020
0c5a2f1
Fix test that now throws ODE.
jpobst Jan 8, 2020
228614b
Update Java.Interop-MonoAndroid.csproj
jpobst Jan 8, 2020
3d47261
[JniEnvironment] Revert change that changed an NSE to an ODE.
jpobst Jan 15, 2020
11e5e72
Fix a few more nullable warnings.
jpobst Feb 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trigger:

# Global variables
variables:
DotNetCoreVersion: 2.1.701
DotNetCoreVersion: 3.1.x
HostedMac: Hosted Mac Internal
HostedWinVS2019: Hosted Windows 2019 with VS2019

Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
version: $(DotNetCoreVersion)

- script: |
dotnet tool install --global boots --version 1.0.0.291
dotnet tool install --global boots
boots https://download.mono-project.com/archive/6.4.0/macos-10-universal/MonoFramework-MDK-6.4.0.198.macos10.xamarin.universal.pkg
displayName: Install Mono 6.4

Expand Down
6 changes: 6 additions & 0 deletions src/Java.Interop/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@

[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:Java.Interop.JniRuntime.JniMarshalMemberBuilder.IsDirectMethod(System.Reflection.ParameterInfo[])~System.Boolean")]
[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:Java.Interop.JniRuntime.JniValueManager.GetJniIdentityHashCode(Java.Interop.JniObjectReference)~System.Int32")]
[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~P:Java.Interop.JniFieldInfo.Name")]
[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~P:Java.Interop.JniFieldInfo.Signature")]
[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~P:Java.Interop.JniMethodInfo.Name")]
[assembly: SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~P:Java.Interop.JniMethodInfo.Signature")]

[assembly: SuppressMessage ("Performance", "CA1823:Avoid unused private fields", Justification = "Used for native interop", Scope = "type", Target = "~T:Java.Interop.JavaException")]
[assembly: SuppressMessage ("Performance", "CA1823:Avoid unused private fields", Justification = "Used for native interop", Scope = "type", Target = "~T:Java.Interop.JavaObject")]
Expand All @@ -85,3 +89,5 @@

[assembly: SuppressMessage ("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "<Pending>", Scope = "member", Target = "~M:Java.Interop.JniEnvironment.Exceptions.Throw(Java.Interop.JniObjectReference)")]
[assembly: SuppressMessage ("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "<Pending>", Scope = "member", Target = "~M:Java.Interop.JniEnvironment.Exceptions.ThrowNew(Java.Interop.JniObjectReference,System.String)")]

[assembly: SuppressMessage ("Usage", "CA2213:Disposable fields should be disposed", Justification = "<Pending>", Scope = "member", Target = "~F:Java.Interop.JniRuntime.valueManager")]
7 changes: 5 additions & 2 deletions src/Java.Interop/Java.Interop-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<BaseIntermediateOutputPath>obj-MonoAndroid\</BaseIntermediateOutputPath>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<Import Project="..\..\Configuration.props" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug</OutputPath>
<DefineConstants>DEBUG;INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS</DefineConstants>
<DefineConstants>DEBUG;INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<DocumentationFile>..\..\bin\Debug\Java.Interop.xml</DocumentationFile>
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
</PropertyGroup>
Expand All @@ -37,8 +39,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS</DefineConstants>
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<DocumentationFile>..\..\bin\Release\Java.Interop.xml</DocumentationFile>
<JNIEnvGenPath>..\..\bin\BuildRelease</JNIEnvGenPath>
</PropertyGroup>
Expand Down
42 changes: 31 additions & 11 deletions src/Java.Interop/Java.Interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</ProjectGuid>
<NoWarn>1591</NoWarn>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS</DefineConstants>
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\..\bin\Debug</OutputPath>
<DocumentationFile>..\..\bin\Debug\Java.Interop.xml</DocumentationFile>
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
<DefineConstants>DEBUG;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Gendarme|AnyCPU' ">
<OutputPath>..\..\bin\GendarmeDebug</OutputPath>
<DefineConstants>DEBUG;$(DefineConstants)</DefineConstants>
<DocumentationFile>..\..\bin\Debug\Java.Interop.xml</DocumentationFile>
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
<DefineConstants>$(DefineConstants);DEBUG;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\..\bin\Release</OutputPath>
<DocumentationFile>..\..\bin\Release\Java.Interop.xml</DocumentationFile>
<JNIEnvGenPath>..\..\bin\BuildRelease</JNIEnvGenPath>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Java.Interop\JniLocationException.cs" />
Expand Down Expand Up @@ -64,9 +61,32 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj">
<Project>{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}</Project>
<Name>jnienv-gen</Name>
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Java.Interop\JavaPrimitiveArrays.cs">
<DependentUpon>JavaPrimitiveArrays.tt</DependentUpon>
</Compile>
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Java.Interop\JniBuiltinMarshalers.cs">
<DependentUpon>JniBuiltinMarshalers.tt</DependentUpon>
</Compile>
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Java.Interop\JniPeerMembers.JniFields.cs">
<DependentUpon>JniPeerMembers.JniFields.tt</DependentUpon>
</Compile>
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Java.Interop\JniPeerMembers.JniInstanceMethods_Invoke.cs">
<DependentUpon>JniPeerMembers.JniInstanceMethods_Invoke.tt</DependentUpon>
</Compile>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<VersionControlPolicy>
<CommitMessageStyle Indent="&#x9;" LineAlign="0" IncludeDirectoryPaths="True" />
</VersionControlPolicy>
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>
2 changes: 2 additions & 0 deletions src/Java.Interop/Java.Interop/IJavaPeerable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;

namespace Java.Interop
Expand Down
33 changes: 22 additions & 11 deletions src/Java.Interop/Java.Interop/JavaArray.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#nullable enable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand All @@ -25,6 +28,7 @@ public int Length {
get {return JniEnvironment.Arrays.GetArrayLength (PeerReference);}
}

[MaybeNull]
public abstract T this [int index] {
get;
set;
Expand Down Expand Up @@ -56,7 +60,9 @@ public virtual IEnumerator<T> GetEnumerator ()
{
int len = Length;
for (int i = 0; i < len; ++i)
#pragma warning disable CS8603 // Possible null reference return.
yield return this [i];
#pragma warning restore CS8603 // Possible null reference return.
}

internal static void CheckArrayCopy (int sourceIndex, int sourceLength, int destinationIndex, int destinationLength, int length)
Expand Down Expand Up @@ -98,7 +104,7 @@ internal static IList<T> ToList (IEnumerable<T> value)
return value.ToList ();
}

internal IList<T> ToTargetType (Type targetType, bool dispose)
internal IList<T> ToTargetType (Type? targetType, bool dispose)
{
if (TargetTypeIsCurrentType (targetType))
return this;
Expand All @@ -113,26 +119,27 @@ internal IList<T> ToTargetType (Type targetType, bool dispose)
throw CreateMarshalNotSupportedException (GetType (), targetType);
}

internal virtual bool TargetTypeIsCurrentType (Type targetType)
internal virtual bool TargetTypeIsCurrentType ([NotNullWhen (false)]Type? targetType)
{
return targetType == null || targetType == typeof (JavaArray<T>);
}

internal static Exception CreateMarshalNotSupportedException (Type sourceType, Type targetType)
internal static Exception CreateMarshalNotSupportedException (Type sourceType, Type? targetType)
{
throw new NotSupportedException (
string.Format ("Do not know how to marshal a '{0}' into a '{1}'.",
sourceType.FullName, targetType.FullName));
return new NotSupportedException (
string.Format ("Do not know how to marshal a `{0}`{1}.",
sourceType.FullName,
targetType != null ? $" into a `{targetType.FullName}`" : ""));
}

internal static IList<T> CreateValue<TArray> (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type targetType, ArrayCreator<TArray> creator)
internal static IList<T> CreateValue<TArray> (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type? targetType, ArrayCreator<TArray> creator)
where TArray : JavaArray<T>
{
return creator (ref reference, transfer)
.ToTargetType (targetType, dispose: true);
}

internal static JniValueMarshalerState CreateArgumentState<TArray> (IList<T> value, ParameterAttributes synchronize, Func<IList<T>, bool, TArray> creator)
internal static JniValueMarshalerState CreateArgumentState<TArray> (IList<T>? value, ParameterAttributes synchronize, Func<IList<T>, bool, TArray> creator)
where TArray : JavaArray<T>
{
if (value == null)
Expand All @@ -149,10 +156,10 @@ internal static JniValueMarshalerState CreateArgumentState<TArray> (IList<T
return new JniValueMarshalerState (a);
}

internal static void DestroyArgumentState<TArray> (IList<T> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
internal static void DestroyArgumentState<TArray> (IList<T>? value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
where TArray : JavaArray<T>
{
var source = (TArray) state.PeerableValue;
var source = (TArray?) state.PeerableValue;
if (source == null)
return;

Expand Down Expand Up @@ -187,7 +194,9 @@ internal virtual void CopyToList (IList<T> list, int index)
{
int len = Length;
for (int i = 0; i < len; i++) {
#pragma warning disable CS8601 // Possible null reference assignment.
list [index + i] = this [i];
#pragma warning restore CS8601 // Possible null reference assignment.
}
}

Expand Down Expand Up @@ -217,9 +226,11 @@ bool IList.IsFixedSize {
}
}

object IList.this [int index] {
object? IList.this [int index] {
get {return this [index];}
#pragma warning disable 8601
set {this [index] = (T) value;}
#pragma warning restore 8601
}

void ICollection.CopyTo (Array array, int index)
Expand Down
10 changes: 6 additions & 4 deletions src/Java.Interop/Java.Interop/JavaException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;

namespace Java.Interop
Expand All @@ -8,7 +10,7 @@ unsafe public class JavaException : Exception, IJavaPeerable
internal const string JniTypeName = "java/lang/Throwable";
readonly static JniPeerMembers _members = new JniPeerMembers (JniTypeName, typeof (JavaException));

public string JavaStackTrace { get; private set; }
public string? JavaStackTrace { get; private set; }
public int JniIdentityHashCode { get; private set; }
public JniManagedPeerStates JniManagedPeerState { get; private set; }

Expand Down Expand Up @@ -177,7 +179,7 @@ public override unsafe int GetHashCode ()
return _members.InstanceMethods.InvokeVirtualInt32Method ("hashCode.()I", this, null);
}

static string GetMessage (ref JniObjectReference reference, JniObjectReferenceOptions transfer)
static string? GetMessage (ref JniObjectReference reference, JniObjectReferenceOptions transfer)
{
if (transfer == JniObjectReferenceOptions.None)
return null;
Expand All @@ -187,7 +189,7 @@ static string GetMessage (ref JniObjectReference reference, JniObjectReferenceOp
return JniEnvironment.Strings.ToString (ref s, JniObjectReferenceOptions.CopyAndDispose);
}

static Exception GetCause (ref JniObjectReference reference, JniObjectReferenceOptions transfer)
static Exception? GetCause (ref JniObjectReference reference, JniObjectReferenceOptions transfer)
{
if (transfer == JniObjectReferenceOptions.None)
return null;
Expand All @@ -197,7 +199,7 @@ static Exception GetCause (ref JniObjectReference reference, JniObjectReferenceO
return JniEnvironment.Runtime.GetExceptionForThrowable (ref e, JniObjectReferenceOptions.CopyAndDispose);
}

unsafe string GetJavaStack (JniObjectReference handle)
unsafe string? GetJavaStack (JniObjectReference handle)
{
using (var StringWriter_class = new JniType ("java/io/StringWriter"))
using (var PrintWriter_class = new JniType ("java/io/PrintWriter")) {
Expand Down
4 changes: 3 additions & 1 deletion src/Java.Interop/Java.Interop/JavaObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;

namespace Java.Interop
Expand Down Expand Up @@ -125,7 +127,7 @@ public override unsafe int GetHashCode ()
return _members.InstanceMethods.InvokeVirtualInt32Method ("hashCode.()I", this, null);
}

public override unsafe string ToString ()
public override unsafe string? ToString ()
{
var lref = _members.InstanceMethods.InvokeVirtualObjectMethod (
"toString.()Ljava/lang/String;",
Expand Down
Loading