I am currently writing a private Java API for myself that uses Class
's to allow a certain portion of the API (a stats keeping portion) to be extended without changing the underlying usage. I like this method, but for some reason, whenever the API attempts to execute theClass.newInstance()
, it throws an error like so:
java.lang.IllegalAccessError: tried to access method me.duper51.DuperFramework.utils.player.StatsObject.<init>()V from class me.duper51.Skyrings.stats.SkyringsStats
at me.duper51.Skyrings.stats.SkyringsStats.<init>(SkyringsStats.java:14) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_131]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_131]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_131]
at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_131]
at me.duper51.DuperFramework.utils.player.PlaygroundPlayer.getStats(PlaygroundPlayer.java:71) ~[?:?]
at me.duper51.Skyrings.listeners.GameListener.lambda$getReplacements$0(GameListener.java:65) ~[?:?]
at me.duper51.DuperFramework.utils.scoreboard.SidebarOption.update(SidebarOption.java:44) ~[?:?]
at me.duper51.DuperFramework.utils.scoreboard.SidebarOption.update(SidebarOption.java:53) ~[?:?]
at me.duper51.DuperFramework.utils.scoreboard.SidebarManager.updateAll(SidebarManager.java:75) ~[?:?]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-e1ebe52]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-e1ebe52]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
where me.duper51.Skyrings.stats.SkyringsStats
is the extended class, and me.duper51.DuperFramework.utils.player.StatsObject
is the base class.
The extended object looks something like the following:
public class SkyringsStats extends StatsObject {
public SkyringsStats() {
super();
}
private int kills = 0;
private int wins = 0;
private int totalPlays = 0;
private int deaths = 0;
public void incrementKills() {
kills++;
}
public void incrementDeaths() {
deaths++;
}
public void incrementTotalPlays() {
totalPlays++;
}
public void incrementWins() {
wins++;
}
public int getKills() {
return kills;
}
public int getWins() {
return kills;
}
public int getDeaths() {
return kills;
}
public int getGamesPlayed() {
return kills;
}
}
As requested in another answer, this is the output of javap -p me.duper51.DuperFramework.utils.player.StatsObject
Compiled from "StatsObject.java"
public class me.duper51.DuperFramework.utils.player.StatsObject {
private java.util.UUID pUUID;
public me.duper51.DuperFramework.utils.player.StatsObject();
void setpUUID(java.util.UUID);
public void commitChanges(me.duper51.DuperFramework.GamePlugin);
private static void lambda$commitChanges$0();
}
In my case, I was using Jenkins as a method to build this application. The JAR was then loaded into another application. There were multiple versions of the DuperAPI package, and the first JAR to be loaded got superiority. This caused the discrepancy and ultimately caused the error. I adjusted the shading system to not include the files that were not needed from the upstream API.