Jannyboy11 / ScalaPluginLoader

PluginLoader for Bukkit that provides Scala runtime classes and enhanced APIs.
https://www.spigotmc.org/resources/scalaloader.59568/
GNU Lesser General Public License v3.0
26 stars 10 forks source link

Can't use ScalaLoader with java 8 anymore #3

Closed EpiCanard closed 3 years ago

EpiCanard commented 3 years ago

Hello,

Issue type: Bug Minecraft version : Spigot 1.16.3 ScalaLoader version : 0.13.7

Description :

In the commit b6891a27 you changed the java version used for compilation from 8 to 11.

This change prevent to use your plugin with java below the version 11 (like java 8), many servers still use java 8 and it could be a good idea to keep the compatibility with java 8. When I try to load ScalaLoader inside server launched with java 8 I get this error.

org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: xyz/janboerman/scalaloader/ScalaLoader has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:394) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at org.bukkit.craftbukkit.v1_16_R2.CraftServer.loadPlugins(CraftServer.java:383) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at net.minecraft.server.v1_16_R2.DedicatedServer.init(DedicatedServer.java:183) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:808) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_265]
Caused by: java.lang.UnsupportedClassVersionError: xyz/janboerman/scalaloader/ScalaLoader has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_265]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756) ~[?:1.8.0_265]
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[?:1.8.0_265]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:163) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:96) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_265]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_265]
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_265]
        at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_265]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.16.3.jar:git-Spigot-17d78db-5c77bd2]
        ... 7 more

Is this change mandatory ? If not, is it possible to rollback to java 8 version ?

Best Regards

Jannyboy11 commented 3 years ago

Hello there.

The reason I upgraded to Java 11 was so that I could use [InputStream#readAllBytes()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html#readAllBytes()) which got added in Java 9. It is used by the classbytes transformation system which makes the event api work so nicely.

While it is possible to achieve the same functionality on Java 8, it may perform worse. Rolling back to an older version of ScalaLoader will work, but you won't be able to use the event api, and the bukkit pluginloader classybytes transformations won't be applied either.

I can look into creating a multi-release jar that will work on both Java 8 and 11 to really solve the issue. It will then pick the more effecient method on Java 11. I don't want Java 11 users to take the performance hit that is required for Java 8 users.

I am currently working on providing a better api for ConfigurationSerializable classes, but when that's done then the multi-release jar will be the first item on my todo-list. (A pull request would be very welcome too!)

PS. I wasn't actually expecting people to use Java 8 anymore; You can have a look at this video to hear some reasons why you would want to upgrade to 11 or 15: Panel: Ask the Java Architects

PPS. I should also mention that somebody else has forked the project to make it run on Java 8 again: 8-bit-gaming/ScalaPluginLoader

Edit: I should also mention that I will not support Java 8 indefinitely. Once the java compiler drops support for --release 8, or ASM or Scala drop supprt for Java 8, then I will too.

EpiCanard commented 3 years ago

Hello,

Don't waste time creating a version of ScalaPluginLoader compatible with Java 8. Your changes are justified.

If I asked you, it's to avoid forcing users of my plugin to use Java 11 or higher. But if downgrading the ScalaPluginLoader to java 8 means reducing its quality and performance, upgrade to java 11 (or higher) is a cost that can be taken :) And if users don't want to use java 11 they can still use the old version of my plugin (developed in java).

Thanks for you answer. That's all for me :)

Jannyboy11 commented 3 years ago

Alright thank you. I won't putting any effort into Java 8 compability then any time soon. I think the best lesson to take from this is "don't make assumptions, measure" so I might include the bStats library by the time of the next release.

EpiCanard commented 3 years ago

@Jannyboy11 To give you an idea of why I'm worried about migrating them to java 11. https://bstats.org/global/bukkit#javaVersion You can see the distribution of the java version used for minecraft servers and there is a large part of java 8.

Jannyboy11 commented 3 years ago

It is such a shame that so many people are still on such an inferior version of Java. Oh well - time to reopen the issue then.

EpiCanard commented 3 years ago

I agree...

Jannyboy11 commented 3 years ago

Hi, I know this thread has been inactive for a while, so here's a little update. My current development code now compiles again with --release 8. There's just some bugs in the implementation for the new configurationseralization api so those need to be ironed out first. I expect to release the new version somewhere at the end of the month.

EpiCanard commented 3 years ago

Hello, Thank you for the news. Good luck with the fix of the serialization.

Jannyboy11 commented 3 years ago

As of 8a8ad424 ScalaLoader supports Java 8 again. The archive file is now a Multi-Release jar, so that it can pick better implementations of certain classes when running on Java 11 or newer. I won't deploy to SpigotMC yet because there are still three parts missing to the enhanced configuration-serializatoin api (support for sum types, arrays and some collections, and scala standard library classes)

Edit: At https://bstats.org/plugin/bukkit/ScalaLoader/9150 you will now be able to see which versions of Java and Scala are most used by servers running ScalaLoader.

EpiCanard commented 3 years ago

Thanks a lot for your work :)

Jannyboy11 commented 3 years ago

I decided to release on SpigotMC again because one of the three missing features of configuration serialization api is now implemented, and a new version of Scala was released. I won't be completing the other two features anytime soon due to some real life issues. Read the update notes here.

EpiCanard commented 3 years ago

Thank you. No problem :) Good luck for your life issues.