Skip to content

Commit

Permalink
Avoid race condition crashes when handling duplicate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Aug 18, 2024
1 parent fe081e8 commit 9f0dbda
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,22 @@ public void loadClasses(IIdentifierRenamer renamer) {
excludedMatcher = Pattern.compile(excludedRegex).matcher("");
}

// Filter any duplicate classes

List<StructClass> ownClasses = context.getOwnClasses();
List<StructClass> classes = new ArrayList<>();
Set<String> names = new LinkedHashSet<>();

for (StructClass cl : ownClasses) {
if (names.add(cl.qualifiedName)) {
classes.add(cl);
} else {
DecompilerContext.getLogger().writeMessage("Skipping processing already existing class: " + cl.qualifiedName, IFernflowerLogger.Severity.ERROR);
}
}

// create class nodes
for (StructClass cl : context.getOwnClasses()) {
for (StructClass cl : classes) {
if (excludedMatcher != null && excludedMatcher.reset(cl.qualifiedName).matches()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public String path() {
}
}


@Override
public String toString() {
return "E[" + basePath + "]";
}
}
}
12 changes: 7 additions & 5 deletions src/org/jetbrains/java/decompiler/struct/ContextUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand Down Expand Up @@ -150,13 +147,18 @@ public void save(final Function<String, StructClass> loader) throws IOException
ForkJoinPool pool = new ForkJoinPool(threads, namingScheme(), null, true);
final DecompilerContext rootContext = DecompilerContext.getCurrentContext();
final List<ClassContext> toDump = new ArrayList<>(classEntries.size());
Set<String> seen = new LinkedHashSet<>();

// collect classes
for (int i = 0; i < classEntries.size(); i++) {
StructClass cl = loader.apply(classEntries.get(i));
String entryName = decompiledData.getClassEntryName(cl, classEntries.get(i));
if (entryName != null) {
toDump.add(new ClassContext(cl, entryName));
if (seen.add(cl.qualifiedName)) {
toDump.add(new ClassContext(cl, entryName));
} else {
DecompilerContext.getLogger().writeMessage("Skipping writing already existing class: " + cl.qualifiedName, IFernflowerLogger.Severity.ERROR);
}
}
}

Expand Down

0 comments on commit 9f0dbda

Please sign in to comment.