Blankj/AndroidUtilCode · warning · UnsupportedOperationException

u can't instantiate me...

Error message

u can't instantiate me...

What it means

PinyinUtils is a final utility class with a private constructor that throws UnsupportedOperationException. All Chinese-to-Pinyin helpers are static; instantiation is forbidden by design.

Source

Thrown at lib/subutil/src/main/java/com/blankj/subutil/util/PinyinUtils.java:16

package com.blankj.subutil.util;

import androidx.collection.SimpleArrayMap;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 16/11/16
 *     desc  : 拼音相关工具类
 * </pre>
 */
public final class PinyinUtils {

    private PinyinUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 汉字转拼音
     *
     * @param ccs 汉字字符串(Chinese characters)
     * @return 拼音
     */
    public static String ccs2Pinyin(final CharSequence ccs) {
        return ccs2Pinyin(ccs, "");
    }

    /**
     * 汉字转拼音
     *
     * @param ccs   汉字字符串(Chinese characters)
     * @param split 汉字拼音之间的分隔符
     * @return 拼音

View on GitHub (pinned to 7b4caf9e54)

Solutions

  1. Call the static methods, e.g. PinyinUtils.ccs2Pinyin(text) / PinyinUtils.getPinyinFirstLetter(c); never instantiate.
  2. Exclude PinyinUtils from reflective scanning.
  3. Remove newInstance paths targeting the class.

Example fix

// before
PinyinUtils p = reflectNew(PinyinUtils.class); // throws

// after
String py = PinyinUtils.ccs2Pinyin("你好");
Defensive patterns

Strategy: validation

Validate before calling

// PinyinUtils is static-only; never instantiate.
String py = PinyinUtils.ccs2Pinyin(text);

Type guard

private static boolean isStaticUtility(Class<?> c) {
    return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);
}

Prevention

When it happens

Trigger: Reflective instantiation or unsafe allocation of PinyinUtils rather than calling its static methods.

Common situations: Reflection/DI/serialization frameworks that build arbitrary classes; tests that reflectively scaffold utilities.

Related errors


AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14). Data as JSON: /api/errors/0ef3e979d4454f82. Report an issue: GitHub.