{"record":{"id":"14f3b305bb180858","repo":"TheAlgorithms/Java","slug":"bcoeffs-must-be-of-size-got","errorCode":null,"errorMessage":"bCoeffs must be of size {}, got {}","messagePattern":"bCoeffs must be of size (.+?), got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/audiofilters/IIRFilter.java","lineNumber":58,"sourceCode":"    /**\n     * Set coefficients\n     *\n     * @param aCoeffs Denominator coefficients\n     * @param bCoeffs Numerator coefficients\n     * @throws IllegalArgumentException if {@code aCoeffs} or {@code bCoeffs} is\n     * not of size {@code order}, or if {@code aCoeffs[0]} is 0.0\n     */\n    public void setCoeffs(double[] aCoeffs, double[] bCoeffs) throws IllegalArgumentException {\n        if (aCoeffs.length != order) {\n            throw new IllegalArgumentException(\"aCoeffs must be of size \" + order + \", got \" + aCoeffs.length);\n        }\n\n        if (aCoeffs[0] == 0.0) {\n            throw new IllegalArgumentException(\"aCoeffs.get(0) must not be zero\");\n        }\n\n        if (bCoeffs.length != order) {\n            throw new IllegalArgumentException(\"bCoeffs must be of size \" + order + \", got \" + bCoeffs.length);\n        }\n\n        for (int i = 0; i < order; i++) {\n            coeffsA[i] = aCoeffs[i];\n            coeffsB[i] = bCoeffs[i];\n        }\n    }\n\n    /**\n     * Process a single sample\n     *\n     * @param sample the sample to process\n     * @return the processed sample\n     */\n    public double process(double sample) {\n        double result = 0.0;\n\n        // Process","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/audiofilters/IIRFilter.java#L40-L76","documentation":"Thrown by IIRFilter.setCoeffs when the numerator coefficient array's length does not equal the filter's configured order. Like the aCoeffs check, this prevents a partial copy or out-of-bounds access in the loop that fills coeffsB. The length is compared against `order`, not `order + 1`.","triggerScenarios":"Calling `setCoeffs(a, b)` where `b.length != filterOrder`. For example, `new IIRFilter(4)` then `setCoeffs(a, new double[3])` throws 'bCoeffs must be of size 4, got 3'.","commonSituations":"Numerator and denominator arrays of different lengths coming from a design tool; off-by-one when assembling the coefficient list; reusing arrays sized for a different filter order.","solutions":["Ensure bCoeffs has exactly `order` elements.","Pad or truncate the numerator array to match order before passing.","Confirm both a and b arrays are generated with the same order used at construction."],"exampleFix":"// before\nf.setCoeffs(a, new double[3]);  // throws: must be of size 4, got 3\n\n// after\ndouble[] bFixed = Arrays.copyOf(b, 4);\nf.setCoeffs(a, bFixed);","handlingStrategy":"validation","validationCode":"if (bCoeffs.length != order) throw new IllegalArgumentException(\"bCoeffs length \" + bCoeffs.length + \" != order \" + order);\nfilter.setCoeffs(aCoeffs, bCoeffs);","typeGuard":"public static boolean bCoeffsMatchOrder(double[] b, int order) {\n    return b != null && b.length == order;\n}","tryCatchPattern":"try {\n    filter.setCoeffs(a, b);\n} catch (IllegalArgumentException e) {\n    filter.setCoeffs(a, Arrays.copyOf(b, order));\n}","preventionTips":["Keep a and b arrays the same length, equal to order.","Generate both from the same design routine.","Validate lengths together before calling setCoeffs."],"tags":["audio","filter","argument-validation","illegalargumentexception","off-by-one"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}