{"record":{"id":"db26f85927d2f946","repo":"JessYanCoding/AndroidAutoSize","slug":"you-can-t-instantiate-me-db26f8","errorCode":null,"errorMessage":"you can't instantiate me!","messagePattern":"you can't instantiate me!","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"autosize/src/main/java/me/jessyan/autosize/utils/Preconditions.java","lineNumber":30,"sourceCode":" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage me.jessyan.autosize.utils;\n\nimport android.os.Looper;\n\n/**\n * ================================================\n * Created by JessYan on 26/09/2016 13:59\n * <a href=\"mailto:jess.yan.effort@gmail.com\">Contact me</a>\n * <a href=\"https://github.com/JessYanCoding\">Follow me</a>\n * ================================================\n */\npublic final class Preconditions {\n\n    private Preconditions() {\n        throw new IllegalStateException(\"you can't instantiate me!\");\n    }\n\n    public static void checkArgument(boolean expression) {\n        if (!expression) {\n            throw new IllegalArgumentException();\n        }\n    }\n\n    public static void checkArgument(boolean expression, Object errorMessage) {\n        if (!expression) {\n            throw new IllegalArgumentException(String.valueOf(errorMessage));\n        }\n    }\n\n    public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) {\n        if (!expression) {\n            throw new IllegalArgumentException(format(errorMessageTemplate, errorMessageArgs));\n        }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/JessYanCoding/AndroidAutoSize/blob/e402ecdd998ea07549513ac08c12e9f097f3b48c/autosize/src/main/java/me/jessyan/autosize/utils/Preconditions.java#L12-L48","documentation":"This is a deliberate sentinel guard, not a normal runtime error. Preconditions is a final, static-only assertion helper (checkMainThread, etc.), so its constructor is private; any `new Preconditions()` call (including via reflection) throws this IllegalStateException immediately. The input at fault is the instantiation attempt itself; correct usage is to invoke its static check methods.","triggerScenarios":"Calling new Preconditions() or reflecting it.","commonSituations":"DI/codegen instantiating all classes; developers mimicking instance-based validators.","solutions":["Call static methods like Preconditions.checkNotNull(value) directly","Remove the instantiation","Exclude the class from auto-instantiation tooling"],"exampleFix":"// before\nPreconditions p = new Preconditions();\n// after\nPreconditions.checkNotNull(value, \"value must not be null\");","handlingStrategy":"try-catch","validationCode":"if (Modifier.isPrivate(Preconditions.class.getDeclaredConstructor().getModifiers())) { /* use static check methods */ }","typeGuard":"boolean isUtilityClass(Class<?> c) { return Modifier.isPrivate(c.getDeclaredConstructors()[0].getModifiers()); }","tryCatchPattern":"try { new Preconditions(); } catch (IllegalStateException e) { /* expected: static assertion helper */ }","preventionTips":["Use Preconditions.checkArgument/checkState/checkNotNull statically","Don't instantiate assertion helpers in helper objects or DI graphs"],"tags":["java","static-class","assertions"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e402ecdd998ea07549513ac08c12e9f097f3b48c","analyzedAt":"2026-09-07T15:05:42.094Z","contentChangedAt":"2026-09-07T15:05:42.094Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}