Repository navigation
Tests that only need a project load its index, and an index names the JDK it holds #140
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
base: 1.21.1
Are you sure you want to change the base?
Changes from all commits
a0ee901
2751799
747455e
49dcbc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.github.minecraft_ta.totalDebugCompanion.bytecode.RuntimeSnapshotBytecodeSource.Source; | ||
| import com.github.minecraft_ta.totaldebug.storage.AtomicFiles; | ||
| import com.github.minecraft_ta.totaldebug.storage.JsonFiles; | ||
| import com.github.minecraft_ta.totaldebug.storage.RuntimeInventory.ModuleKind; | ||
| import com.github.minecraft_ta.totaldebug.storage.RuntimeInventory.RuntimeModule; | ||
| import com.github.tth05.jindex.ClassIndex; | ||
| import com.google.gson.JsonArray; | ||
|
|
@@ -119,6 +120,9 @@ static Manifest read(Path file) throws IOException { | |
| if (JsonFiles.integer(json, "format") != FORMAT) { | ||
| throw new IOException("Unsupported runtime index format: " + file); | ||
| } | ||
| if (!javaVersion().equals(JsonFiles.string(json, "javaVersion"))) { | ||
| throw new IOException("The index holds the classes of another Java runtime: " + JsonFiles.string(json, "javaVersion")); | ||
| } | ||
| List<Source> sources = new ArrayList<>(); | ||
| var ids = new HashSet<Integer>(); | ||
| for (var value : JsonFiles.array(json, "sources")) { | ||
|
|
@@ -154,12 +158,26 @@ static void requireSourcePaths(Manifest manifest) throws IOException { | |
| if (!Files.isRegularFile(path) && !Files.isDirectory(path)) { | ||
| throw new IOException("Prepared runtime source is unavailable: " + path); | ||
| } | ||
| if (source.module().kind() == ModuleKind.JAVA_RUNTIME && !path.equals(javaHome())) { | ||
| throw new IOException("The index holds the classes of another Java runtime: " + path); | ||
|
Comment on lines
+161
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Companion uses a different JVM from the game—explicitly supported for IDE/offline launches—and that JVM is upgraded or replaced in place, the saved game inventory ID remains unchanged and this path equality still accepts the old cache. The loaded index then describes the previous JDK while AGENTS.md reference: AGENTS.md:L7-L7 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 747455e: the manifest records |
||
| } | ||
| } | ||
| } | ||
|
|
||
| /** The Java runtime whose classes an index holds: the one Companion runs on. */ | ||
| static Path javaHome() { | ||
| return Path.of(System.getProperty("java.home")).toAbsolutePath().normalize(); | ||
| } | ||
|
|
||
| /** The version and build of that runtime, which an update in place changes. */ | ||
| static String javaVersion() { | ||
| return System.getProperty("java.runtime.version"); | ||
| } | ||
|
|
||
| private static JsonObject toJson(Manifest manifest) { | ||
| JsonObject json = new JsonObject(); | ||
| json.addProperty("format", FORMAT); | ||
| json.addProperty("javaVersion", javaVersion()); | ||
| json.addProperty("sourceKind", manifest.identity().kind().name()); | ||
| json.addProperty("sourceIdentity", manifest.identity().value()); | ||
| if (!manifest.detail().isBlank()) json.addProperty("detail", manifest.detail()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Companion is launched with a valid but non-normalized
java.homesuch as/opt/jdk/.or a relative path, every generated Java-runtimeSourcestores an absolute normalized path, but this comparison uses the raw system-property path. The paths therefore compare unequal; cached indexes are rejected, and rebuilding also fails whenIndexCache.writevalidates the newly written manifest. Return an absolute normalized path fromjavaHome()before comparing it.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2751799:
javaHome()returns the absolute, normalized path, asSourcestores it.aJavaHomeWrittenWithRedundantPartsIsTheSameRuntimesetsjava.hometo<home>/.; it fails without the fix.