pxb1988/dex2jar · error · DexWriteException
dup clz: " + name
Error message
dup clz: " + name
What it means
ConstPool.putClassDefItem() refuses to define the same class name twice; the pool already contains a ClassDefItem for the given type, so it throws DexWriteException('dup clz: <name>'). The dex format allows only one class_def entry per type.
Solutions
- Deduplicate input classes before generation (keep one definition per class name)
- Create a new DexFileWriter/Dex file for the second definition or skip already-added classes
- Log and drop the second definition instead of adding it
Example fix
// before
for (Clz c : allClasses) writer.putClassDefItem(...);
// after
Set<String> seen = new HashSet<>();
for (Clz c : allClasses) { if (seen.add(c.name)) writer.putClassDefItem(...); } Defensive patterns
Strategy: validation
Validate before calling
if (poolContainsClass(name)) { skipOrMerge(name); } else { writer.putClassDefItem(access, name, superClz, itfs); } Try / catch
try { writer.putClassDefItem(access, name, superClz, itfs); } catch (DexWriteException e) { if (String.valueOf(e.getMessage()).startsWith("dup clz:")) { /* skip duplicate */ return; } throw e; } Prevention
- Deduplicate class inputs (Set of class names) before generation
- Use a fresh DexFileWriter per output dex
- Handle multi-release/merged classpaths where duplicates are common
When it happens
Trigger: Calling putClassDefItem (directly or via DexFileWriter's class APIs) twice for the same class name within one DexFileWriter.
Common situations: Merging multiple class sources that both contain the same class; re-running a generation step against an existing DexFileWriter instance; duplicate class files on the input classpath (different casings resolved to same name).
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Odex unsupported.
- Magic unsupported.
- Endian_tag unsupported
- Encountered RESTART_LOCAL on new v
- Invalid extended opcode encountered
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/add2389884904471.
Report an issue: GitHub.
Appendix: source
Thrown at dex-writer/src/main/java/com/googlecode/d2j/dex/writer/item/ConstPool.java:223
public AnnotationsDirectoryItem putAnnotationDirectoryItem() {
AnnotationsDirectoryItem aDirectoryItem = new AnnotationsDirectoryItem();
annotationsDirectoryItems.add(aDirectoryItem);
return aDirectoryItem;
}
public AnnotationItem uniqAnnotationItem(AnnotationItem key) {
AnnotationItem v = annotationItems.get(key);
if (v == null) {
annotationItems.put(key, key);
return key;
}
return v;
}
public ClassDefItem putClassDefItem(int accessFlag, String name, String superClass, String[] itfClass) {
TypeIdItem type = uniqType(name);
if (classDefs.containsKey(type)) {
throw new DexWriteException("dup clz: " + name);
}
ClassDefItem classDefItem = new ClassDefItem();
classDefItem.accessFlags = accessFlag;
classDefItem.clazz = type;
if (superClass != null) {
classDefItem.superclazz = uniqType(superClass);
}
if (itfClass != null && itfClass.length > 0) {
classDefItem.interfaces = putTypeList(Arrays.asList(itfClass));
}
classDefs.put(type, classDefItem);
return classDefItem;
}
public FieldIdItem uniqField(Field field) {
return uniqField(field.getOwner(), field.getName(), field.getType());
}
View on GitHub (pinned to b5bda4fb49)