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

Unable to get ItemMeta #721

Open
2 tasks done
Timeout-Timo opened this issue Dec 23, 2022 · 6 comments
Open
2 tasks done

Unable to get ItemMeta #721

Timeout-Timo opened this issue Dec 23, 2022 · 6 comments
Labels
bug-exception Issue describes a bug in MockBukkit that prevent plugins from being tested.

Comments

@Timeout-Timo
Copy link

Timeout-Timo commented Dec 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest version of MockBukkit?

  • I am using the latest version of MockBukkit.

Minecraft Version

1.19

Describe the bug

After updating my tests from 1.18.2 to 1.19.3 there is an ExceptionInInitializerError in ItemFactoryMock.
Inside my test I cannot get any ItemMeta. This is the exception:

java.lang.ExceptionInInitializerError
	at be.seeseemelk.mockbukkit.inventory.ItemFactoryMock.getItemMetaClass(ItemFactoryMock.java:63)
	at be.seeseemelk.mockbukkit.inventory.ItemFactoryMock.getItemMeta(ItemFactoryMock.java:99)
	at org.bukkit.inventory.ItemStack.getItemMeta(ItemStack.java:549)
	at de.rytrox.spicy.item.ItemStackBuilderTest.shouldNotWork(ItemStackBuilderTest.java:72)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.IllegalStateException: paper:doors_settag: DOORS - Expected 10 values, got 11
	at io.papermc.paper.tag.BaseTag.ensureSize(BaseTag.java:170)
	at com.destroystokyo.paper.MaterialTags.<clinit>(MaterialTags.java:106)
	... 74 more

Reproducible Test

    @Test
    public void shouldNotWork() {
        ItemStack item = new ItemStack(Material.STONE);
        ItemMeta meta = item.getItemMeta(); // This line is causing the issue

        meta.setDisplayName("Test");
        item.setItemMeta(meta);

        assertEquals("Test", item.getItemMeta().getDisplayName());
    }

Anything else?

In 1.18.2 it worked fine. I'm using classic Spigot 1.19.3

@thelooter thelooter added the bug-exception Issue describes a bug in MockBukkit that prevent plugins from being tested. label Dec 24, 2022
@Relluem94
Copy link

Same Problem here

java.lang.ExceptionInInitializerError
        at be.seeseemelk.mockbukkit.inventory.ItemFactoryMock.getItemMetaClass(ItemFactoryMock.java:62)
        at be.seeseemelk.mockbukkit.inventory.ItemFactoryMock.getItemMeta(ItemFactoryMock.java:98)
        at org.bukkit.inventory.ItemStack.getItemMeta(ItemStack.java:550)
        at de.relluem94.minecraft.server.spigot.essentials.helpers.ItemHelper.<init>(ItemHelper.java:78)
        at de.relluem94.minecraft.server.spigot.essentials.npc.NPC.<init>(NPC.java:32)
        at de.relluem94.minecraft.server.spigot.essentials.npc.NPC.<init>(NPC.java:25)
        at de.relluem94.minecraft.server.spigot.essentials.api.NPCAPI$1.<init>(NPCAPI.java:26)
        at de.relluem94.minecraft.server.spigot.essentials.api.NPCAPI.init(NPCAPI.java:26)
        at de.relluem94.minecraft.server.spigot.essentials.managers.DatabaseManager.enable(DatabaseManager.java:52)
        at de.relluem94.minecraft.server.spigot.essentials.RelluEssentials.onEnable(RelluEssentials.java:126)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
        at org.bukkit.plugin.java.JavaPluginUtils.setEnabled(JavaPluginUtils.java:25)
        at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.enablePlugin(PluginManagerMock.java:597)
        at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:183)
        at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:168)
        at de.relluem94.minecraft.server.spigot.essentials.RelluEssentialsTest.setUp(RelluEssentialsTest.java:59)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalStateException: paper:doors_settag: DOORS - Expected 11 values, got 12
        at io.papermc.paper.tag.BaseTag.ensureSize(BaseTag.java:171)
        at com.destroystokyo.paper.MaterialTags.<clinit>(MaterialTags.java:106)
        ... 38 more

@md5sha256
Copy link
Contributor

I briefly looked into the commit history of the patch which adds this API on paper. Basically, the tags in MaterialTags are based on the Material enum. So the most likely reason I can think of as to why there is a value mismatch is if the Material enum present at runtime is newer/older than the version MaterialTags is expecting.

The last time the DOORS expected 11 values was on this commit on Mar 15. The commit was part of the effort to update the paper API to 1.19.4. As of writing this comment, DOORS expects 12 values.

As to why this is happening I'm not sure. My best guess is that there is some sort of classpath conflict between your plugin and MockBukkit thus your test environment is using API for say 1.19.3 but MockBukkit is using 1.19.4 (or the other way around).

I'll see if I can get a repro case for my hypothesis but that's my 2 cents for now.

TL;DR Possible classpath conflict causing classes from two different API versions to be present at the test runtime

@Insprill
Copy link
Contributor

Insprill commented Jul 13, 2023

Is this still an issue with the 1.20 versions of MockBukkit 3? I wasn't able to reproduce it using the provided test.

@Relluem94
Copy link

hi @Insprill i will test it with the next release of my plugin

@Insprill
Copy link
Contributor

@Relluem94 Have you gotten around to testing this?

@Relluem94
Copy link

Hi @Insprill i updated to 3.19.1 of MockBukkit-v1.20
now im getting

java.lang.RuntimeException: Failed to instantiate plugin
        at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.loadPlugin(PluginManagerMock.java:421)
        at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.loadPlugin(PluginManagerMock.java:453)
        at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:179)
        at be.seeseemelk.mockbukkit.MockBukkit.load(MockBukkit.java:165)
        at de.relluem94.minecraft.server.spigot.essentials.RelluEssentialsTest.setUp(RelluEssentialsTest.java:54)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.loadPlugin(PluginManagerMock.java:415)
        ... 26 more
Caused by: java.lang.IllegalStateException: JavaPlugin requires org.bukkit.plugin.java.PluginClassLoader
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:53)
        at de.relluem94.minecraft.server.spigot.essentials.RelluEssentials.<init>(RelluEssentials.java:188)
        at RelluEssentialsProxy.<init>(Unknown Source)
        ... 32 more

so i cant test, i try to figure a way out.

is it related with this #755 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-exception Issue describes a bug in MockBukkit that prevent plugins from being tested.
Projects
None yet
Development

No branches or pull requests

5 participants