As background, transient fields are not serialized by Java's serialization mechanisms (which is used by Gradle), which causes an issue as the equals and hashCode methods of Artifact (introduced by the aforementioned commit) relies on one such field. This causes a NullPointerException if something attempts to call these two methods on a freshly deserialized Artifact instance.
The solution here[^1] is to move creating and assigning the values of these fields to their respective getters (in the case of comparableVersion, a new package-private getter), such that their values are created on-demand and cached for future calls.
This PR also cleans up the formatting of the getters in Artifact from the single-line getter format.
[^1]: In a Discord conversation on the Forge project discord server, this was the chosen option; the other alternative solution were to remove the transient modifier from the fields (which would include data in the serialized form that can already be recreated from the already-serialized fields).
This PR fixes an issue from https://github.com/MinecraftForge/ForgeGradle/commit/b6ac471841ef54d4f3e668bf71c8f400824a26a2 by moving the construction and assignment of the
transient
fields inArtifact
from the constructor to getters, fixing any method using these values to work even after deserialization.As background,
transient
fields are not serialized by Java's serialization mechanisms (which is used by Gradle), which causes an issue as theequals
andhashCode
methods ofArtifact
(introduced by the aforementioned commit) relies on one such field. This causes aNullPointerException
if something attempts to call these two methods on a freshly deserializedArtifact
instance.The solution here[^1] is to move creating and assigning the values of these fields to their respective getters (in the case of
comparableVersion
, a new package-private getter), such that their values are created on-demand and cached for future calls.This PR also cleans up the formatting of the getters in
Artifact
from the single-line getter format.[^1]: In a Discord conversation on the Forge project discord server, this was the chosen option; the other alternative solution were to remove the
transient
modifier from the fields (which would include data in the serialized form that can already be recreated from the already-serialized fields).