{"record":{"id":"09f013d4e18ce908","repo":"shwenzhang/AndResGuard","slug":"failed-to-read-page-resource","errorCode":null,"errorMessage":"Failed to read <page> resource","messagePattern":"Failed to read <page> resource","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/apksigner/ApkSignerTool.java","lineNumber":495,"sourceCode":"      return;\n    }\n    if ((warningsTreatedAsErrors) && (warningsEncountered)) {\n      System.exit(1);\n      return;\n    }\n  }\n\n  private static void printUsage(String page) {\n    try (BufferedReader in = new BufferedReader(new InputStreamReader(\n        ApkSignerTool.class.getResourceAsStream(page),\n        StandardCharsets.UTF_8\n    ))) {\n      String line;\n      while ((line = in.readLine()) != null) {\n        System.out.println(line);\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Failed to read \" + page + \" resource\");\n    }\n  }\n\n  private static byte[] readFully(File file) throws IOException {\n    ByteArrayOutputStream result = new ByteArrayOutputStream();\n    try (FileInputStream in = new FileInputStream(file)) {\n      drain(in, result);\n    }\n    return result.toByteArray();\n  }\n\n  private static void drain(InputStream in, OutputStream out) throws IOException {\n    byte[] buf = new byte[65536];\n    int chunkSize;\n    while ((chunkSize = in.read(buf)) != -1) {\n      out.write(buf, 0, chunkSize);\n    }\n  }","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/apksigner/ApkSignerTool.java#L477-L513","documentation":"printUsage reads a usage/help page from the classpath via getResourceAsStream and prints it. When reading the stream throws an IOException, it is rethrown as a RuntimeException \"Failed to read <page> resource\". This means the tool could not read its own bundled help text, typically because the resource is missing from the packaged jar or the stream failed mid-read.","triggerScenarios":"Running main/sign/verify which calls printUsage(\"/apksigner/help/...\") when usage output is required, and the classpath resource referenced by `page` is absent (getResourceAsStream returns null, causing NPE/IOException on read) or the underlying stream throws IOException while reading.","commonSituations":"Running a repackaged/proguarded jar where the help text resources were stripped; invoking apksigner classes from a classpath that excludes the resource directory; corrupted or partially extracted build artifact.","solutions":["Use the intact AndResGuard/apksigner build artifact so the usage text resources (e.g. /apksigner/help/*.txt) are on the classpath.","If running from an IDE or fat jar, add a resources-inclusion rule (keep the help resource files) to the build config.","Report/patch printUsage to handle a null stream explicitly instead of relying on IOException.","As a workaround, consult apksigner usage documentation offline instead of triggering the help page."],"exampleFix":"// before\n} catch (IOException e) {\n  throw new RuntimeException(\"Failed to read \" + page + \" resource\");\n}\n// after\n} catch (IOException | NullPointerException e) {\n  throw new RuntimeException(\"Failed to read \" + page + \" resource - resource missing on classpath\", e);\n}","handlingStrategy":"try-catch","validationCode":"java\nURL url = ApkSignerTool.class.getResource(page);\nif (url == null) {\n    throw new IllegalStateException(\"Usage page resource missing from classpath: \" + page);\n}","typeGuard":null,"tryCatchPattern":"java\ntry {\n    printUsage(page);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to read\")) {\n        System.err.println(\"Help resources missing; see online docs instead.\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep the apksigner help resource files in the packaged jar (check build resource-exclusion rules).","Verify jar contents with `unzip -l apksigner.jar | grep help` before distributing.","When shading/proguarding, add keep rules for resource files."],"tags":["java","classpath","resource-not-found","cli"],"backgroundTag":"resource-not-found","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}