shwenzhang/AndResGuard · error · RuntimeException
Error while mapping file
Error message
Error while mapping file
What it means
AndResGuard throws this RuntimeException when reading a resource mapping file (the keep-mapping file supplied in Configuration) fails with an IOException. The catch block in the config-parsing loop swallows the original IOException and rethrows this generic message, so the underlying cause (missing file, permission, malformed stream) is lost. It indicates the mapping file could not be fully read while loading configuration.
Solutions
- Verify the mapping file path in the AndResGuard configuration points to an existing, readable file before running the build
- Open/read the file with plain FileReader in a test to surface the real IOException (file not found vs permission)
- Add the mapping file to version control or the CI artifact pipeline so it exists at build time
- Wrap file access with explicit checks (File.exists(), canRead()) and log the path to ease diagnosis
Example fix
// before
File mapping = new File(config.mappingFile);
parseMapping(mapping);
// after
File mapping = new File(config.mappingFile);
if (!mapping.isFile() || !mapping.canRead()) {
throw new IllegalArgumentException("Mapping file missing or unreadable: " + mapping.getAbsolutePath());
}
parseMapping(mapping); Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(mappingPath);
if (!f.isFile()) throw new IllegalStateException("Mapping file missing: " + f.getAbsolutePath());
if (!f.canRead()) throw new IllegalStateException("Mapping file not readable: " + f.getAbsolutePath()); Try / catch
try {
parseConfiguration();
} catch (RuntimeException e) {
if ("Error while mapping file".equals(e.getMessage())) {
// verify mapping file existence/permissions, then retry or fail fast with a clear message
} else throw e;
} Prevention
- Check file existence/readability in config validation before running the build
- Commit the mapping file or fetch it as a CI artifact
- Use absolute paths in configuration to avoid working-directory surprises
When it happens
Trigger: Calling the public Configuration parsing entry point with a mapping file path that does not exist, is unreadable (permissions), is a directory, or whose stream breaks mid-read (br.readLine() throws IOException).
Common situations: Typo in the mapping file path in build.gradle config; file deleted or moved between builds; running on CI where the mapping file wasn't checked in; insufficient file permissions; file on a network mount that drops the connection.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Failed to read resource
- No keystore passwords
- No key passwords
- No passwords
- Not an RSA, EC, or DSA private key
AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12).
Data as JSON: /api/errors/1099f23f0c36ce29.
Report an issue: GitHub.
Appendix: source
Thrown at AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java:527
}
HashMap<String, String> namesMap;
if (typeMap.containsKey(typeName)) {
namesMap = typeMap.get(typeName);
} else {
namesMap = new HashMap<>();
}
namesMap.put(beforename, aftername);
typeMap.put(typeName, namesMap);
mOldResMapping.put(packageName, typeMap);
}
}
}
line = br.readLine();
}
} catch (IOException ex) {
throw new RuntimeException("Error while mapping file");
} finally {
try {
br.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
View on GitHub (pinned to e4df245d82)