{"record":{"id":"10d01034e88c4efd","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-10d010","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"lib/subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java","lineNumber":43,"sourceCode":"\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 16/11/13\n *     desc  : 定位相关工具类\n * </pre>\n */\npublic final class LocationUtils {\n\n    private static final int TWO_MINUTES = 1000 * 60 * 2;\n\n    private static OnLocationChangeListener mListener;\n    private static MyLocationListener       myLocationListener;\n    private static LocationManager          mLocationManager;\n\n    private LocationUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n\n//    /**\n//     * you have to check for Location Permission before use this method\n//     * add this code <uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /> to your Manifest file.\n//     * you have also implement LocationListener and passed it to the method.\n//     *\n//     * @param Context\n//     * @param LocationListener\n//     * @return {@code Location}\n//     */\n//\n//    @SuppressLint(\"MissingPermission\")\n//    public static Location getLocation(Context context, LocationListener listener) {\n//        Location location = null;\n//        try {\n//            mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/subutil/src/main/java/com/blankj/subutil/util/LocationUtils.java#L25-L61","documentation":"LocationUtils is a final utility class with a private constructor that throws UnsupportedOperationException. It holds only static fields/listeners and exposes static methods; instantiation is explicitly forbidden.","triggerScenarios":"Reflective instantiation or unsafe allocation of LocationUtils rather than using its static API.","commonSituations":"Reflection-driven frameworks or tests attempting to construct the class; misconfigured DI treating it as a bean.","solutions":["Call the static methods, e.g. LocationUtils.registerLocation(...) / unregisterLocation(); never instantiate.","Exclude LocationUtils from reflective scanning/bean creation.","Remove any newInstance path targeting the class."],"exampleFix":"// before\nLocationUtils loc = reflectNew(LocationUtils.class); // throws\n\n// after\nLocationUtils.registerLocation(UPDATE_MIN_TIME, UPDATE_MIN_DISTANCE, listener);","handlingStrategy":"validation","validationCode":"// LocationUtils is static-only; never instantiate.\nLocationUtils.registerLocation(minTime, minDistance, listener);","typeGuard":"private static boolean isStaticUtility(Class<?> c) {\n    return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);\n}","tryCatchPattern":null,"preventionTips":["Use LocationUtils via its static methods only.","Exclude LocationUtils from reflective scanning/bean creation.","Remove reflection that constructs the class."],"tags":["android","utility","instantiation","reflection","location"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}