-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-20586 .NET: Fix JNI string conversion causing node crash (#10985)
When working with `jstring` in JNI, we used `GetStringUTFChars`, which returns Java-specific "modified UTF-8" characters, then passed those characters to `Encoding.UTF8.GetString` in .NET. However, "modified UTF-8" is not true UTF-8, and cannot be correctly decoded by .NET standard library; in some cases it can even cause `OverflowException` and crash the node. The fix is to use `GetStringChars`, which returns UTF-16 characters without any quirks. Both Java and .NET use UTF-16 to represent strings internally, so this approach is also simpler and faster. The fix (and the bug) does not affect user data serialization - JNI strings are only used for logging, console output, instance names, and config paths.
- Loading branch information
Showing
9 changed files
with
205 additions
and
79 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
modules/core/src/test/java/org/apache/ignite/platform/PlatformConsoleWriteTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ignite.platform; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.ignite.cluster.ClusterNode; | ||
import org.apache.ignite.compute.ComputeJob; | ||
import org.apache.ignite.compute.ComputeJobAdapter; | ||
import org.apache.ignite.compute.ComputeJobResult; | ||
import org.apache.ignite.compute.ComputeTaskAdapter; | ||
import org.apache.ignite.internal.util.typedef.F; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Task to test Java console output. | ||
*/ | ||
public class PlatformConsoleWriteTask extends ComputeTaskAdapter<byte[], Object> { | ||
/** {@inheritDoc} */ | ||
@NotNull @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, | ||
@Nullable byte[] arg) { | ||
return Collections.singletonMap(new Job(arg), F.first(subgrid)); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Nullable @Override public String reduce(List<ComputeJobResult> results) { | ||
return results.get(0).getData(); | ||
} | ||
|
||
/** | ||
* Job. | ||
*/ | ||
private static class Job extends ComputeJobAdapter { | ||
/** */ | ||
private final byte[] arg; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param arg arg. | ||
*/ | ||
private Job(byte[] arg) { | ||
this.arg = arg; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Nullable @Override public String execute() { | ||
String str = new String(arg, StandardCharsets.UTF_16LE); | ||
System.out.println(str); | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.