Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

bug(value): 关于Integer与Long类型的内部读取异常 #17

Closed
flowerinsnowdh opened this issue Dec 5, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@flowerinsnowdh
Copy link
Contributor

问题简述

在一个ConfiguredValue中获取Long值,可能会发生转换异常

问题来源

配置内容

@HeaderComment("发送消息的冷却")
public static final ConfiguredValue<Long> CHAT_COOLDOWN = ConfiguredValue.of(Long.class, 3000L);

配置文件内

# 发送消息的冷却
chat-cooldown: 3000

调用

@SuppressWarnings("ConstantConditions")
long cd = Config.CHAT_COOLDOWN.getOrDefault();

报错

[14:24:37] [Async Chat Thread - #0/WARN]: java.lang.IllegalArgumentException: Cannot cast value to java.lang.Long
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.shaded.cc.carm.lib.configuration.core.function.ConfigValueParser.lambda$castObject$5(ConfigValueParser.java:54)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.shaded.cc.carm.lib.configuration.core.function.ConfigValueParser.lambda$compose$1(ConfigValueParser.java:28)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.shaded.cc.carm.lib.configuration.core.value.type.ConfiguredValue.get(ConfiguredValue.java:60)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.shaded.cc.carm.lib.configuration.core.value.ConfigValue.getOptional(ConfigValue.java:91)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.shaded.cc.carm.lib.configuration.core.value.ConfigValue.getOrDefault(ConfigValue.java:77)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at online.flowerinsnow.chatrecord.listener.ChatListener.onChat(ChatListener.java:66)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.lang.reflect.Method.invoke(Method.java:498)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:74)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:517)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1111)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1026)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.java:39)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[14:24:37] [Async Chat Thread - #0/WARN]: 	at java.lang.Thread.run(Thread.java:853)

同样的环境下,将Long改为Integer即可避免报错
效果:我也不知道为什么,该异常抛出后,当前线程不会死亡,可以继续往下跑,但获取到的内容始终是默认值(例如3000L)
该异常不是偶然,是必定异常

环境

openjdk version "1.8.0_312"
paper 1.8.8 445
Ubuntu 22.04.1 LTS

@flowerinsnowdh flowerinsnowdh added the bug Something isn't working label Dec 5, 2022
@flowerinsnowdh
Copy link
Contributor Author

补充:环境依赖是cc.carm.lib:mineconfiguration-bukkit:2.1.0

@CarmJos
Copy link
Owner

CarmJos commented Dec 5, 2022

这个问题我也发现很久了,但是一直以来没有思路修复,我再想想如何解决吧,也希望您能帮我看看。

@flowerinsnowdh
Copy link
Contributor Author

@CarmJos
Copy link
Owner

CarmJos commented Dec 5, 2022

请将本议题移向父项目EasyConfiguration。

@CarmJos CarmJos closed this as completed Dec 5, 2022
@CarmJos CarmJos transferred this issue from CarmJos/MineConfiguration Dec 5, 2022
@CarmJos CarmJos reopened this Dec 5, 2022
@CarmJos CarmJos changed the title 一个内部异常 bug(value): 关于Integer与Long类型的内部读取异常 Dec 5, 2022
@CarmJos CarmJos closed this as completed in 6f97166 Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants