Skip to content

Commit 40c21ff

Browse files
authored
Merge pull request diffblue#284 from diffblue/marek/bugfix/do_not_generate_empty_jar
SEC-142: Bugfix: prevent generation of empty JAR (when no class files are found).
2 parents dddebaf + ebf78b5 commit 40c21ff

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

driver/mkbench.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,19 @@ def collect_java_binaries(app_binary_dirs, temp_dir, output_json, verbosity):
146146
classes_temp_dir = os.path.join(temp_dir, "CLASSES")
147147
assert not os.path.exists(classes_temp_dir)
148148
os.makedirs(classes_temp_dir)
149-
for class_src_pathname, class_file_info in classes_info["results"].items():
150-
class_dst_pathname = os.path.join(classes_temp_dir, class_file_info["name"].replace(".", "/") + ".class")
151-
if not os.path.isdir(os.path.dirname(class_dst_pathname)):
152-
os.makedirs(os.path.dirname(class_dst_pathname))
153-
if os.path.isfile(class_dst_pathname) and not filecmp.cmp(class_src_pathname, class_dst_pathname):
154-
print("WARNING: Detected multiple versions of the Java class file '" +
155-
class_src_pathname + "'. Picking one arbitrarily!")
156-
shutil.copyfile(class_src_pathname, class_dst_pathname)
157-
classes_jar_file = os.path.join(temp_dir, "collected_classes.jar")
158-
with utility.PushCwd(classes_temp_dir):
159-
os.system("jar cf \"" + classes_jar_file + "\" .")
160-
java_binaries.jar_files.append(classes_jar_file)
149+
if len(classes_info["results"]) != 0:
150+
for class_src_pathname, class_file_info in classes_info["results"].items():
151+
class_dst_pathname = os.path.join(classes_temp_dir, class_file_info["name"].replace(".", "/") + ".class")
152+
if not os.path.isdir(os.path.dirname(class_dst_pathname)):
153+
os.makedirs(os.path.dirname(class_dst_pathname))
154+
if os.path.isfile(class_dst_pathname) and not filecmp.cmp(class_src_pathname, class_dst_pathname):
155+
print("WARNING: Detected multiple versions of the Java class file '" +
156+
class_src_pathname + "'. Picking one arbitrarily!")
157+
shutil.copyfile(class_src_pathname, class_dst_pathname)
158+
classes_jar_file = os.path.join(temp_dir, "collected_classes.jar")
159+
with utility.PushCwd(classes_temp_dir):
160+
os.system("jar cf \"" + classes_jar_file + "\" .")
161+
java_binaries.jar_files.append(classes_jar_file)
161162

162163
# We write the lists of collected Java binaries into the output JSON file.
163164
if not os.path.isdir(os.path.dirname(output_json)):

0 commit comments

Comments
 (0)