Blankj/AndroidUtilCode · error · UnsupportedOperationException
u can't instantiate me...
Error message
u can't instantiate me...
What it means
ZipUtils is a final static-only utility for zip/unzip operations. Its private constructor throws UnsupportedOperationException to prevent instantiation. All public methods (zipFiles, unzipFile, etc.) are static.
Source
Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/ZipUtils.java:34
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/08/27
* desc : utils about zip
* </pre>
*/
public final class ZipUtils {
private static final int BUFFER_LEN = 8192;
private ZipUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
/**
* Zip the files.
*
* @param srcFiles The source of files.
* @param zipFilePath The path of ZIP file.
* @return {@code true}: success<br>{@code false}: fail
* @throws IOException if an I/O error has occurred
*/
public static boolean zipFiles(final Collection<String> srcFiles,
final String zipFilePath)
throws IOException {
return zipFiles(srcFiles, zipFilePath, null);
}
/**
* Zip the files.View on GitHub (pinned to 7b4caf9e54)
Solutions
- Use static methods: ZipUtils.zipFiles(files, path) instead of constructing the class.
- Provide a Gson InstanceCreator / Jackson mixin returning a sentinel so the constructor is not invoked.
- Use Mockito.mockStatic for mocking rather than constructing ZipUtils.
- Keep the class final with a private constructor.
Example fix
// before ZipUtils zu = new ZipUtils(); // after ZipUtils.zipFiles(fileList, "/sdcard/out.zip");
Defensive patterns
Strategy: validation
Validate before calling
if (Modifier.isFinal(ZipUtils.class.getModifiers())) {
throw new IllegalStateException("ZipUtils is static-only.");
} Prevention
- Call ZipUtils.zipFiles(...) statically.
- Register InstanceCreator/mixin for JSON fields.
- Use Mockito.mockStatic for mocking.
- Keep final + private constructor.
When it happens
Trigger: Reflective instantiation via ZipUtils.class.getDeclaredConstructor().setAccessible(true).newInstance(), or transitively through Gson/Jackson deserialization, Mockito/PowerMock, Kotlin reflection, or a DI classpath scan.
Common situations: Serialization frameworks binding a field to ZipUtils; mock frameworks in tests; coverage probes; accidental `new ZipUtils()` after weakening modifiers.
Related errors
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
- u can't instantiate me...
AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14).
Data as JSON: /api/errors/6e77e1072b8b7030.
Report an issue: GitHub.