Skip to content
New issue

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

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

Already on GitHub? # to your account

[Java.Interop] JniTypeSignature & CultureInfo, empty strings #1002

Merged
merged 1 commit into from
Jun 30, 2022

Conversation

jonpryor
Copy link
Member

Fixes: #335

Context: 920ea64

Commit 920ea64 optimized JniTypeManager.AssertSimpleReference() by
using string.IndexOf(char).

This dovetails with Issue #335, which wanted to optimize
JniTypeSignature by removing calls to string.Contains(string).

Fix #335, and update the JniTypeSignature constructor to use
string.IndexOf(char) instead of string.Contains(string), and use
string indexers instead of string.StartsWith() and
string.EndsWith().

Java.Interop.dll has no remaining usage of string.StartsWith()
and string.EndsWith().

Additionally, update JniTypeSignature so that the empty string ""
is not treated as a valid type signature. This is arguably a
breaking change, but the empty string never made sense, and would
throw an IndexOutOfRangeException with JniTypeManager.Parse().

Fixes: dotnet#335

Context: 920ea64

Commit 920ea64 optimized `JniTypeManager.AssertSimpleReference()` by
using `string.IndexOf(char)`.

This dovetails with Issue dotnet#335, which wanted to optimize
`JniTypeSignature` by removing calls to `string.Contains(string)`.

Fix dotnet#335, and update the `JniTypeSignature` constructor to use
`string.IndexOf(char)` instead of `string.Contains(string)`, and use
string indexers instead of `string.StartsWith()` and
`string.EndsWith()`.

`Java.Interop.dll` has no remaining usage of `string.StartsWith()`
and `string.EndsWith()`.

Additionally, update `JniTypeSignature` so that the empty string `""`
is *not* treated as a valid type signature.  This is arguably a
breaking change, but the empty string never made sense, *and* would
throw an `IndexOutOfRangeException` with `JniTypeManager.Parse()`.
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, looks good, I see this taking some time in a dotnet new maui app:

image

Comment on lines 43 to 45
public JniTypeSignature (string? simpleReference, int arrayRank = 0, bool keyword = false)
{
if (simpleReference != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is simpleReference allowed to be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanpeppers: it's a struct, and thus always has a default constructor, i.e. new JniTypeSignature() is always "valid" (can't/won't throw), and couldn't be overridden at the time (that may have since changed, but default provides original semantics). Given that, and that new JniTypeSignature() is semantically identical to new JniTypeSignature(null) and new JniTypeSignature(null, 0, false), why should new JniTypeSigature(null) throw?

Perhaps it should throw, but at the time it didn't make sense to me.

@jonpryor
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor jonpryor merged commit 99c68a8 into dotnet:main Jun 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
Status: Done & Blogged
Development

Successfully merging this pull request may close these issues.

JniTypeSignature uses CultureInfo
2 participants