{"record":{"id":"f8d6179b435c24f3","repo":"iBotPeaches/Apktool","slug":"could-not-extract-resource","errorCode":null,"errorMessage":"Could not extract resource: ","messagePattern":"Could not extract resource: ","errorType":"exception","errorClass":"BrutException","httpStatus":null,"severity":"error","filePath":"brut.j.util/src/main/java/brut/util/Jar.java","lineNumber":68,"sourceCode":"    public static File extractToTmp(Class<?> clz, String name) throws BrutException {\n        return extractToTmp(clz, name, \"brut_util_Jar_\");\n    }\n\n    public static File extractToTmp(Class<?> clz, String name, String tmpPrefix) throws BrutException {\n        try (InputStream in = clz.getResourceAsStream(name)) {\n            if (in == null) {\n                throw new FileNotFoundException(name);\n            }\n            long suffix = ThreadLocalRandom.current().nextLong();\n            suffix = suffix > Long.MIN_VALUE ? Math.abs(suffix) : 0;\n            File fileOut = File.createTempFile(tmpPrefix, suffix + \".tmp\");\n            fileOut.deleteOnExit();\n\n            BrutIO.copyAndClose(in, Files.newOutputStream(fileOut.toPath()));\n\n            return fileOut;\n        } catch (IOException ex) {\n            throw new BrutException(\"Could not extract resource: \" + name, ex);\n        }\n    }\n}\n","sourceCodeStart":50,"sourceCodeEnd":72,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.j.util/src/main/java/brut/util/Jar.java#L50-L72","documentation":"Thrown by brut.util.Jar when extracting a classpath resource to a temporary file fails. The inner cause is usually FileNotFoundException (resource not found: getResourceAsStream returned null) but any IOException during stream copy or temp-file creation is wrapped the same way. The message appends the resource name that failed.","triggerScenarios":"Jar.extract(...)/resource-lookup call where the named resource is absent from the classpath/jar (wrong name, leading slash mismatch, case difference), or where File.createTempFile / the copy stream fails (disk full, permissions on java.io.tmpdir).","commonSituations":"Bundled binaries (e.g. aapt, native helpers) missing from the shaded/fat jar; resources renamed between library versions; running from an IDE where resource dirs differ from the packaged jar; resource name built with a hardcoded '/' or wrong package prefix; read-only or full temp directory.","solutions":["Verify the resource exists on the same classloader the code uses: getClass().getClassLoader().getResourceAsStream(name) != null","Fix the resource name — check exact case, package path, and whether a leading '/' is expected; print getClass().getProtectionDomain().getCodeSource() to confirm which jar is loaded","If packaging a fat/shaded jar, ensure resource transform rules (maven-shade etc.) did not drop or relocate the resource","Check the temp filesystem: df $TMPDIR / free disk, and -Djava.io.tmpdir override if the default is unwritable"],"exampleFix":"// before\nFile f = Jar.extract(\"/prebuilt/aapt\"); // name wrong or resource missing\n\n// after\nString name = \"/prebuilt/aapt\";\nif (Jar.class.getResourceAsStream(name) == null) {\n    throw new IllegalStateException(\"Resource not on classpath: \" + name);\n}\nFile f = Jar.extract(name);","handlingStrategy":"validation","validationCode":"String name = \"/prebuilt/aapt\";\nboolean present = Jar.class.getClassLoader().getResourceAsStream(name) != null;\nFile f = present ? Jar.extract(name) : throwOrFallback();","typeGuard":null,"tryCatchPattern":"try {\n    File f = Jar.extract(name);\n} catch (BrutException e) {\n    if (e.getCause() instanceof FileNotFoundException) {\n        // resource missing from classpath: packaging bug, fail loudly\n        throw new IllegalStateException(\"bundled resource missing: \" + name, e);\n    }\n    throw e; // IO error on copy/temp file: transient, may retry\n}","preventionTips":["Add a startup assertion that every required classpath resource resolves before doing real work","Pin the library version so bundled-resource names do not drift under you","Test resource extraction from a packaged jar, not just the IDE classpath"],"tags":["classpath","resources","packaging","java"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}