ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.15k stars 110 forks source link

Exception when trying to join a CompletableFuture #447

Open moican opened 7 months ago

moican commented 7 months ago

Hello, I have converted a jar to c# for framework net7.0-windows all the code seems to be working but an exception is thrown when trying to use the method join over a CompletableFuture.

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')' System.Private.CoreLib.dll!System.Collections.ArrayList.this[int].get(int index) IKVM.Runtime.dll!IKVM.Runtime.JNI.JNIGlobalRefTable.Unwrap(nint z) IKVM.Runtime.dll!IKVM.Runtime.JNI.JavaVM.AttachCurrentThreadImpl(IKVM.Runtime.JNI.JavaVM* pJVM, void penv, IKVM.Runtime.JNI.JavaVMAttachArgs pAttachArgs, bool asDaemon) IKVM.Runtime.dll!IKVM.Runtime.JNI.JavaVM.AttachCurrentThreadAsDaemon(IKVM.Runtime.JNI.JavaVM pJVM, void penv, void* args)

I have tried using binaries for windows-x86 & x64.

Any advice would be appreciated.

moican commented 7 months ago

Sorry I forgot to clarify that I am using IKVM version 8.7.1

NightOwl888 commented 7 months ago

Any chance you can provide a repro project?

And how are you converting the .jar? IkvmReference, MavenReference, ikvmc, etc.

moican commented 7 months ago

I tried IkvmReference and also MavenReference, the jar I am using is based on amazon.awssdk.crt

software.amazon.awssdk.crt aws-crt 0.28.0

I will try to create a repro project with my own CompletableFuture.

Thanks for your quick response

moican commented 7 months ago

I was unable to reproduce this error with my own code. I have created a repro project in my repository, the code is basically a java class using some amazon libraries

package testing;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CompletableFuture;

import static com.amazonaws.services.s3.internal.Constants.MB;

public class ListBuckets {
    public CompletableFuture listBuckets(String accessId, String secret, String host, int port) throws URISyntaxException {
        S3CrtHttpConfiguration httpConf = S3CrtHttpConfiguration.builder()
                .trustAllCertificatesEnabled(true)
                .build();

        AwsCredentialsProvider creds = StaticCredentialsProvider.create(AwsBasicCredentials.create(accessId, secret));

        S3AsyncClient s3AsyncClient = S3AsyncClient.crtBuilder()
                .credentialsProvider(creds)
                .checksumValidationEnabled(false)
                .targetThroughputInGbps(1.0)
                .region(Region.EU_CENTRAL_2)
                .endpointOverride(new URI("http://" + host + ":" + port))
                .httpConfiguration(httpConf)
                .maxConcurrency(20)
                .minimumPartSizeInBytes(8L * MB)
                .build();

        return s3AsyncClient.listBuckets();
    }
}

with these maven dependencies

<dependencies>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3-transfer-manager</artifactId>
            <version>2.21.19</version>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk.crt</groupId>
            <artifactId>aws-crt</artifactId>
            <version>0.28.0</version>
            <classifier>windows-x86_64</classifier>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>url-connection-client</artifactId>
            <version>2.21.19</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.12.451</version>
        </dependency>
</dependencies>

And a console application with this code:

var listBuckets = new testing.ListBuckets();

var future = listBuckets.listBuckets("XXX", "YYY", "localhost", 8080);

future.join();

Console.ReadLine();
wasabii commented 6 months ago

I finally took a look at this. Got it running, reproduces. But, without digging into the AWS libraries, I can't tell what's going on. It looks like they're starting native threads or something, and trying to use JNI to attach them? And not checking error results apparently, since they're passing in a null pointer into JNI.

But this is too large for me to spend much time on. I'm not going to have time to go through the entire AWS SDK, including all their C code, to figure out where and why it's failing.

I'd request a much more narrow test case.