{"record":{"id":"7e615b8b679a36b4","repo":"MuntashirAkon/AppManager","slug":"the-number-of-input-and-output-files-are-not-the-same-7e615b","errorCode":null,"errorMessage":"The number of input and output files are not the same.","messagePattern":"The number of input and output files are not the same\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/crypto/OpenPGPCrypto.java","lineNumber":187,"sourceCode":"    @WorkerThread\n    private void doAction(Intent intent, boolean waitForResult) throws IOException {\n        if (mIsFileMode) {\n            doActionForFiles(intent, waitForResult);\n        } else {\n            doActionForStream(intent, waitForResult);\n        }\n    }\n\n    @WorkerThread\n    private void doActionForFiles(Intent intent, boolean waitForResult) throws IOException {\n        mErrorFlag = false;\n        // `files` is never null here\n        if (mInputFiles.length == 0) {\n            Log.d(TAG, \"No files to de/encrypt\");\n            return;\n        }\n        if (mInputFiles.length != mOutputFiles.length) {\n            throw new IOException(\"The number of input and output files are not the same.\");\n        }\n        for (int i = 0; i < mInputFiles.length; i++) {\n            Path inputPath = mInputFiles[i];\n            Path outputPath = mOutputFiles[i];\n            Log.i(TAG, \"Input: %s\\nOutput: %s\", inputPath, outputPath);\n            InputStream is = inputPath.openInputStream();\n            OutputStream os = outputPath.openOutputStream();\n            OpenPgpApi api = new OpenPgpApi(mContext, mService.getService());\n            Intent result = api.executeApi(intent, is, os);\n            mHandler.post(() -> handleResult(result));\n            if (waitForResult) waitForResult();\n            if (mErrorFlag) {\n                outputPath.delete();\n                throw new IOException(\"Error occurred during en/decryption process\");\n            }\n        }\n        // Total success\n    }","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/crypto/OpenPGPCrypto.java#L169-L205","documentation":"OpenPGPCrypto.doActionForFiles pairs input and output files by index and throws IOException if the array lengths differ, since each input needs exactly one output path for the OpenPGP de/en-cryption loop.","triggerScenarios":"Calling doAction (encrypt/decrypt) with mInputFiles.length != mOutputFiles.length, with non-empty input list.","commonSituations":"Building input/output arrays independently (e.g. recursive scan inputs but hand-listed outputs); reusing one output path for several inputs; stale bookkeeping after some inputs were filtered out.","solutions":["Populate both arrays in the same iteration over the file list","Validate equal lengths in the caller before invoking doAction and report a clear error","Derive output names from input names (append .pgp / strip extension) so they stay in sync"],"exampleFix":"// before\ncrypto.doAction(Crypto.OPEN_ENCRYPT, inPaths, Collections.singletonList(outPath).toArray(new Path[0]));\n// after\nPath[] outPaths = new Path[inPaths.length];\nfor (int i = 0; i < inPaths.length; i++) outPaths[i] = inPaths[i].addExtension(\"pgp\");\ncrypto.doAction(Crypto.OPEN_ENCRYPT, inPaths, outPaths);","handlingStrategy":"validation","validationCode":"if (in.length != out.length || in.length == 0) {\n    throw new IllegalArgumentException(\"OpenPGP input/output arrays must be same non-zero length\");\n}","typeGuard":null,"tryCatchPattern":"try { crypto.doAction(Crypto.OPEN_ENCRYPT, in, out); } catch (IOException e) {\n    if (e.getMessage().contains(\"not the same\")) {\n        // fix caller-side path pairing\n    }\n}","preventionTips":["Map each input to an output path in one pass","Unit-test batch encryption with mismatched arrays","Validate lengths at the API boundary"],"tags":["io","files","openpgp","argument-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}