CloudNetService / CloudNet

A modern application that can dynamically and easily deliver Minecraft oriented software
https://cloudnetservice.eu
Apache License 2.0
383 stars 120 forks source link

ApiImplementationGenerator.visitInvokeMethod does not properly handle parameters that occupy 2 slots on the stack #1122

Closed GiantTreeLP closed 1 year ago

GiantTreeLP commented 1 year ago

Stacktrace

[23:35:41] [Server thread/ERROR]: Error occurred while enabling Chestshop v1.0 (Is it up to date?)
dev.derklaro.aerogel.AerogelException: Unable to construct requested value constructor ChestShopStorage((Object[])Object)
Caused by: eu.cloudnetservice.driver.network.rpc.exception.ClassCreationException: Unable to generate api class implementation for class net.tynopia.objects.interfaces.CitybuildSync
    at eu.cloudnetservice.driver.network.rpc.defaults.generation.ApiImplementationGenerator.generateApiImplementation(ApiImplementationGenerator.java:259) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.lambda$generateRPCBasedApi$0(DefaultRPCFactory.java:122) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.lambda$computeIfAbsent$2(UnboundedLocalCache.java:289) ~[caffeine-3.1.2.jar:?]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[?:?]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.computeIfAbsent(UnboundedLocalCache.java:285) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:106) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62) ~[caffeine-3.1.2.jar:?]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.generateRPCBasedApi(DefaultRPCFactory.java:120) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at net.tynopia.Module.injectPlugin(Module.java:361) ~[APILibrary-1.0-SNAPSHOT.jar:?]
    at net.tynopia.chestshop.ChestShopStorage.<init>(ChestShopStorage.java:140) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at dev.derklaro.aerogel.internal.util.MethodHandleUtil.invokeConstructor(MethodHandleUtil.java:88) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.binding.constructors.ConstructingBindingConstructor.lambda$constructProvider$0(ConstructingBindingConstructor.java:92) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.provider.FunctionalContextualProvider.get(FunctionalContextualProvider.java:74) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.DefaultInjectionContext.resolveInstance(DefaultInjectionContext.java:388) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstanceAndRemoveContext(ContextInstanceResolveHelper.java:95) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:79) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:63) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:139) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:121) ~[aerogel-2.0.0.jar:?]
    at net.tynopia.chestshop.ChestShopPlugin.onEnable(ChestShopPlugin.java:21) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:372) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:550) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:667) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugins(CraftServer.java:580) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:644) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:443) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:342) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1123) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:325) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at java.lang.Thread.run(Thread.java:1589) ~[?:?]
Caused by: java.lang.IllegalStateException: Exception defining class net/tynopia/objects/interfaces/CitybuildSync$Impl_G0KSCP2Y9D
    at eu.cloudnetservice.driver.util.define.LookupClassDefiner.defineClass(LookupClassDefiner.java:62) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at eu.cloudnetservice.driver.network.rpc.defaults.generation.ApiImplementationGenerator.generateApiImplementation(ApiImplementationGenerator.java:243) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.lambda$generateRPCBasedApi$0(DefaultRPCFactory.java:122) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.lambda$computeIfAbsent$2(UnboundedLocalCache.java:289) ~[caffeine-3.1.2.jar:?]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[?:?]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.computeIfAbsent(UnboundedLocalCache.java:285) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:106) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62) ~[caffeine-3.1.2.jar:?]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.generateRPCBasedApi(DefaultRPCFactory.java:120) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at net.tynopia.Module.injectPlugin(Module.java:361) ~[APILibrary-1.0-SNAPSHOT.jar:?]
    at net.tynopia.chestshop.ChestShopStorage.<init>(ChestShopStorage.java:140) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at dev.derklaro.aerogel.internal.util.MethodHandleUtil.invokeConstructor(MethodHandleUtil.java:88) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.binding.constructors.ConstructingBindingConstructor.lambda$constructProvider$0(ConstructingBindingConstructor.java:92) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.provider.FunctionalContextualProvider.get(FunctionalContextualProvider.java:74) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.DefaultInjectionContext.resolveInstance(DefaultInjectionContext.java:388) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstanceAndRemoveContext(ContextInstanceResolveHelper.java:95) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:79) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:63) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:139) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:121) ~[aerogel-2.0.0.jar:?]
    at net.tynopia.chestshop.ChestShopPlugin.onEnable(ChestShopPlugin.java:21) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:372) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:550) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:667) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugins(CraftServer.java:580) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:644) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:443) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:342) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1123) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:325) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at java.lang.Thread.run(Thread.java:1589) ~[?:?]
Caused by: java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    net/tynopia/objects/interfaces/CitybuildSync$Impl_G0KSCP2Y9D+0x0000000802799400.setChestShop(JIIILjava/lang/String;Ljava/lang/String;)I @20: iload_2
  Reason:
    Type long_2nd (current frame, locals[2]) is not assignable to integer
  Current Frame:
    bci: @20
    flags: { }
    locals: { 'net/tynopia/objects/interfaces/CitybuildSync$Impl_G0KSCP2Y9D+0x0000000802799400', long, long_2nd, integer, integer, integer, 'java/lang/String', 'java/lang/String' }
    stack: { 'eu/cloudnetservice/driver/network/rpc/RPCSender', 'java/lang/String', '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer }
  Bytecode:
    0000000: 2ab4 0012 1256 1006 bd00 0459 031f b800
    0000010: 5b53 5904 1cb8 004d 5359 051d b800 4d53
    0000020: 5906 1504 b800 4d53 5907 1905 5359 0819
    0000030: 0653 b900 1d03 00b9 0023 0100 c000 2ab6
    0000040: 002e ac                                

    at java.lang.ClassLoader.defineClass0(Native Method) ~[?:?]
    at java.lang.System$2.defineClass(System.java:2371) ~[?:?]
    at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2449) ~[?:?]
    at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2430) ~[?:?]
    at java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2136) ~[?:?]
    at eu.cloudnetservice.driver.util.define.LookupClassDefiner.defineClass(LookupClassDefiner.java:59) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at eu.cloudnetservice.driver.network.rpc.defaults.generation.ApiImplementationGenerator.generateApiImplementation(ApiImplementationGenerator.java:243) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.lambda$generateRPCBasedApi$0(DefaultRPCFactory.java:122) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.lambda$computeIfAbsent$2(UnboundedLocalCache.java:289) ~[caffeine-3.1.2.jar:?]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[?:?]
    at com.github.benmanes.caffeine.cache.UnboundedLocalCache.computeIfAbsent(UnboundedLocalCache.java:285) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:106) ~[caffeine-3.1.2.jar:?]
    at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62) ~[caffeine-3.1.2.jar:?]
    at eu.cloudnetservice.driver.network.rpc.defaults.DefaultRPCFactory.generateRPCBasedApi(DefaultRPCFactory.java:120) ~[wrapper.jar:4.0.0-RC7-ffd31747]
    at net.tynopia.Module.injectPlugin(Module.java:361) ~[APILibrary-1.0-SNAPSHOT.jar:?]
    at net.tynopia.chestshop.ChestShopStorage.<init>(ChestShopStorage.java:140) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at dev.derklaro.aerogel.internal.util.MethodHandleUtil.invokeConstructor(MethodHandleUtil.java:88) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.binding.constructors.ConstructingBindingConstructor.lambda$constructProvider$0(ConstructingBindingConstructor.java:92) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.provider.FunctionalContextualProvider.get(FunctionalContextualProvider.java:74) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.DefaultInjectionContext.resolveInstance(DefaultInjectionContext.java:388) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstanceAndRemoveContext(ContextInstanceResolveHelper.java:95) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:79) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper.resolveInstance(ContextInstanceResolveHelper.java:63) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:139) ~[aerogel-2.0.0.jar:?]
    at dev.derklaro.aerogel.internal.DefaultInjector.instance(DefaultInjector.java:121) ~[aerogel-2.0.0.jar:?]
    at net.tynopia.chestshop.ChestShopPlugin.onEnable(ChestShopPlugin.java:21) ~[Chestshop-1.0-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:372) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:550) ~[MultiPaper-API-1.19.3-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugin(CraftServer.java:667) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at org.bukkit.craftbukkit.v1_19_R2.CraftServer.enablePlugins(CraftServer.java:580) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:644) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:443) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:342) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1123) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:325) ~[multipaper-1.19.3.jar:git-MultiPaper-"0e5a6cf"]
    at java.lang.Thread.run(Thread.java:1589) ~[?:?]
[23:35:41] [Server thread/INFO]: [Chestshop] Disabling Chestshop v1.0

Actions to reproduce

Create an RPC method that has at least one long or double argument and another argument following that.

CloudNet version

4.0.0-RC7-ffd31747

Other

Example method signature: int setChestShop(UUID var1, long var2, int var4, int var5, int var6, String var7, String var8)
This is in reference to the following Discord discussion: https://discord.com/channels/325362837184577536/326369842229805076/1074791477223358495

In essence the code is expecting each parameter to only ever occupy one slot on the stack. Given that longs and doubles use two slots on the stack, the following code tries to read the second half of the long/double as the next parameter: https://github.com/CloudNetService/CloudNet-v3/blob/554d56d5a3a34df3abd827d4ab8a9d8e14afc8e9/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/generation/ApiImplementationGenerator.java#L284-L295

In order to fix this, the two known types of long and double (both explicitly not boxed) need to cause the loop to skip forward one slot. In any case, the methods of ASM work correctly loading a long and then an int: https://asm.ow2.io/javadoc/org/objectweb/asm/Type.html#getOpcode(int).

Issue uniqueness

Tynopia commented 1 year ago

image