From 1fa33117e03232eaf7a4a59ad3ed018d612c9dcd Mon Sep 17 00:00:00 2001 From: Mahmoud Khawaja Date: Tue, 21 Jul 2026 04:58:27 +0300 Subject: [PATCH] Load extension boot classpaths before classpath and vm.boot_classpath Lets an extension override jpf-core's model classes through its own *.boot_classpath, since the first match on the classpath wins. --- .../jpf/jvm/JVMSystemClassLoaderInfo.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/gov/nasa/jpf/jvm/JVMSystemClassLoaderInfo.java b/src/main/gov/nasa/jpf/jvm/JVMSystemClassLoaderInfo.java index 29c40c105..16fe3fcca 100644 --- a/src/main/gov/nasa/jpf/jvm/JVMSystemClassLoaderInfo.java +++ b/src/main/gov/nasa/jpf/jvm/JVMSystemClassLoaderInfo.java @@ -120,13 +120,41 @@ protected void addSystemBootClassPath () { /** * this is the main method to create the ClassPath, which is called from the ctor + * + * Search order (first match wins): + * 1. Extension boot classpaths (any *.boot_classpath property except vm.boot_classpath) + * - this allows extensions to override jpf-core model classes + * 2. Explicit classpath entries (from 'classpath' property) + * 3. jpf-core's vm.boot_classpath + * 4. JRE runtime classes (handled by JRTClassFileContainer in getMatch) */ @Override protected void initializeSystemClassPath (VM vm, int appId) { Config conf = vm.getConfig(); File[] pathElements; - // explicit "classpath[.id]" settings have precedence + // first, load all extension boot classpaths (any property ending in .boot_classpath + // other than vm.boot_classpath) so extensions can override jpf-core model classes + for (Object keyObj : conf.keySet()) { + String key = keyObj.toString(); + if (key.endsWith(".boot_classpath") && !key.equals("vm.boot_classpath")) { + String[] bootPaths = conf.getStringArray(key); + if (bootPaths != null) { + for (String bp : bootPaths) { + bp = bp.trim(); + if (bp.length() > 0 && !bp.equals("")) { + File f = new File(bp); + if (f.exists()) { + addClassPathElement(f.getAbsolutePath()); + log.info("added extension boot classpath (", key, "): ", f.getAbsolutePath()); + } + } + } + } + } + } + + // explicit "classpath[.id]" settings pathElements = getPathElements(conf, "classpath", appId); if (pathElements != null) { for (File f : pathElements) { @@ -134,7 +162,7 @@ protected void initializeSystemClassPath (VM vm, int appId) { } } - // we optionally append boot_classpath + // we optionally append vm.boot_classpath (jpf-core's boot classpath) pathElements = getPathElements(conf, "vm.boot_classpath", appId); if (pathElements != null) { for (File f : pathElements) {