botbuilder-java icon indicating copy to clipboard operation
botbuilder-java copied to clipboard

InaccessibleObjectException - Unable to make field private static final long java.util.ArrayList.serialVersionUID accessible

Open esfomeado opened this issue 2 years ago • 7 comments

Version

bot-integration-spring:4.14.2

Describe the bug

When continuing a conversation I get an InaccessibleObjectException on openjdk17

To Reproduce

Steps to reproduce the behavior:

private final BotFrameworkHttpAdapter adapter;

adapter.continueConversation(...)
java.util.concurrent.CompletionException: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.util.ArrayList.serialVersionUID accessible: module java.base does not "opens java.util" to unnamed module @7c30a502
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.util.ArrayList.serialVersionUID accessible: module java.base does not "opens java.util" to unnamed module @7c30a502
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.microsoft.bot.restclient.Validator.validateClass(Validator.java:73)
at com.microsoft.bot.restclient.Validator.validate(Validator.java:60)
at com.microsoft.bot.restclient.Validator.validateClass(Validator.java:107)
at com.microsoft.bot.restclient.Validator.validate(Validator.java:60)
at com.microsoft.bot.restclient.Validator.validateClass(Validator.java:100)
at com.microsoft.bot.restclient.Validator.validate(Validator.java:60)
at com.microsoft.bot.connector.rest.RestConversations.replyToActivity(RestConversations.java:458)
at com.microsoft.bot.connector.Conversations.replyToActivity(Conversations.java:202)
at com.microsoft.bot.builder.BotFrameworkAdapter.lambda$sendActivities$5(BotFrameworkAdapter.java:618)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)

Expected behavior

It should just work

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Running on openjdk-17 on docker with alpine image

https://openjdk.org/jeps/403

esfomeado avatar Jun 22 '22 18:06 esfomeado

If you add a property to the Activity you can trigger this issue as well when you try to send it.

esfomeado avatar Jun 24 '22 08:06 esfomeado

Investigating

dmvtech avatar Jun 28 '22 00:06 dmvtech

Hi @esfomeado

I don't know that we have done any thorough testing past JDK 8. Possibly some quick tests with JDK 11.

  • Do you have a simple sample that could be used to reproduce the problem?
  • Have you tested with JDK 8 or 11?

dmvtech avatar Jun 28 '22 20:06 dmvtech

I forgot how but I ran into the same problem, a quick fix is to add this VM option: --add-opens java.base/java.util=ALL-UNNAMED

johnmiroki avatar Jun 30 '22 11:06 johnmiroki

@dmvtech

        try
        {
            final ObjectMapper objectMapper = new ObjectMapper().registerModule( new JavaTimeModule() );
            final JsonNode jsonNode = objectMapper.readTree( "{}" );

            final Activity activity = new Activity( ActivityTypes.MESSAGE );
            activity.setProperties( "test", jsonNode );

            final String activityStr = objectMapper.writeValueAsString( activity );
            final Activity activity1 = objectMapper.readValue( activityStr, Activity.class );
            final String activityStr1 = objectMapper.writeValueAsString( activity1 );
            final Activity activity2 = objectMapper.readValue( activityStr1, Activity.class );
        }
        catch ( Exception ex )
        {
            System.out.println( ex );
        }

esfomeado avatar Jun 30 '22 12:06 esfomeado

@johnmiroki Thanks, that's what I'm using as well as workaround.

esfomeado avatar Jun 30 '22 12:06 esfomeado

I have recently run into this issue (with Java 17) while trying to implement a Bot <> Skill communication and calling the handleReplyToActivity of the ChannelServiceHandler. (tracked the problem into the Validator class).

I am just wondering if there is an intention to fix this or if there is a way to disable the validation?

Thanks!

rbuibas avatar May 04 '23 12:05 rbuibas