{"record":{"id":"139724052c740abb","repo":"TheAlgorithms/Java","slug":"utility-class","errorCode":null,"errorMessage":"Utility class","messagePattern":"Utility class","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java","lineNumber":26,"sourceCode":" * Utility class to find the number of unique subsequences that can be\r\n * produced from a given string.\r\n *\r\n * <p> This class contains static methods to compute the unique subsequence count\r\n * using dynamic programming and recursion. It ensures that duplicate characters\r\n * are not counted multiple times in the subsequences.</p>\r\n *\r\n * <p> Author: https://github.com/Tuhinm2002 </p>\r\n */\r\npublic final class UniqueSubsequencesCount {\r\n\r\n    /**\r\n     * Private constructor to prevent instantiation of this utility class.\r\n     * This class should only be used in a static context.\r\n     *\r\n     * @throws UnsupportedOperationException if attempted to instantiate.\r\n     */\r\n    private UniqueSubsequencesCount() {\r\n        throw new UnsupportedOperationException(\"Utility class\");\r\n    }\r\n\r\n    /**\r\n     * Finds the number of unique subsequences that can be generated from\r\n     * the given string.\r\n     *\r\n     * <p> This method initializes a dynamic programming (DP) array and invokes\r\n     * the recursive helper function to compute the subsequence count.</p>\r\n     *\r\n     * @param str the input string from which subsequences are generated\r\n     * @return the total count of unique subsequences\r\n     */\r\n    public static int countSubseq(String str) {\r\n\r\n        // DP array initialized to store intermediate results\r\n        int[] dp = new int[str.length() + 1];\r\n        Arrays.fill(dp, -1);\r\n\r","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/dynamicprogramming/UniqueSubsequencesCount.java#L8-L44","documentation":"Thrown by the private constructor of UniqueSubsequencesCount when reflection or same-package code attempts to instantiate the utility class. The class is final with only static methods; instantiation is intentionally forbidden. Message: 'Utility class'.","triggerScenarios":"Calling new UniqueSubsequencesCount() via reflection (e.g. test frameworks, DI containers, reflective builders); attempting instantiation from within the same package.","commonSituations":"A reflection-based utility tries to instantiate every class; a DI framework scans the package and tries to construct it; a test inadvertently does new UniqueSubsequencesCount().","solutions":["Do not instantiate the class; call its static methods directly (e.g. UniqueSubsequencesCount.count(str)).","Configure reflection/DI tooling to skip final utility classes or to use static-only access.","Exclude the class from reflective instantiation lists."],"exampleFix":"// before (reflection)\nObject u = UniqueSubsequencesCount.class.getDeclaredConstructor().newInstance();\n\n// after\nint c = UniqueSubsequencesCount.count(str);","handlingStrategy":"type-guard","validationCode":"// Do not instantiate; call the static method directly.\nint count = UniqueSubsequencesCount.count(str);","typeGuard":"// Utility class - never instantiate. Access statically:\n// UniqueSubsequencesCount.count(str)","tryCatchPattern":null,"preventionTips":["Configure DI/reflection tooling to skip final utility classes.","Call static methods directly; never new the class.","Document the static-only contract near the class."],"tags":["utility-class","reflection","instantiation","design"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}