{"record":{"id":"1099f23f0c36ce29","repo":"shwenzhang/AndResGuard","slug":"error-while-mapping-file","errorCode":null,"errorMessage":"Error while mapping file","messagePattern":"Error while mapping file","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java","lineNumber":527,"sourceCode":"              }\n\n              HashMap<String, String> namesMap;\n              if (typeMap.containsKey(typeName)) {\n                namesMap = typeMap.get(typeName);\n              } else {\n                namesMap = new HashMap<>();\n              }\n              namesMap.put(beforename, aftername);\n\n              typeMap.put(typeName, namesMap);\n              mOldResMapping.put(packageName, typeMap);\n            }\n          }\n        }\n        line = br.readLine();\n      }\n    } catch (IOException ex) {\n      throw new RuntimeException(\"Error while mapping file\");\n    } finally {\n      try {\n        br.close();\n        fr.close();\n      } catch (IOException e) {\n        e.printStackTrace();\n      }\n    }\n  }\n}\n\n","sourceCodeStart":509,"sourceCodeEnd":539,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java#L509-L539","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nFile mapping = new File(config.mappingFile);\nparseMapping(mapping);\n// after\nFile mapping = new File(config.mappingFile);\nif (!mapping.isFile() || !mapping.canRead()) {\n    throw new IllegalArgumentException(\"Mapping file missing or unreadable: \" + mapping.getAbsolutePath());\n}\nparseMapping(mapping);","handlingStrategy":"try-catch","validationCode":"File f = new File(mappingPath);\nif (!f.isFile()) throw new IllegalStateException(\"Mapping file missing: \" + f.getAbsolutePath());\nif (!f.canRead()) throw new IllegalStateException(\"Mapping file not readable: \" + f.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n    parseConfiguration();\n} catch (RuntimeException e) {\n    if (\"Error while mapping file\".equals(e.getMessage())) {\n        // verify mapping file existence/permissions, then retry or fail fast with a clear message\n    } else throw e;\n}","preventionTips":["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"],"tags":["java","file-io","config","runtime-exception"],"backgroundTag":"file-read-failed","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"}