JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An empty jar entry is added to a jar file.
The programmatic construction of zip or jar archives might be incorrect, when for instance empty entries get added to an archive. This checker looks for inconsistent operation in the creation of such archives.
| Class Name | Empty jar File Archived (Java) | |||
|---|---|---|---|---|
| Significance | reliability | |||
| Mnemonic | JAVA.STRUCT.ARCHIVE.EJF | |||
| Categories |
|
|||
| Availability | Available for Java and Kotlin. |
|||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Empty jar File Archived (Java)" |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipCreator {
public static void main(String[] args) {
try (ZipOutputStream jos = new JarOutputStream(new FileOutputStream(new File("archive.jar")))) {
ZipEntry entry = new ZipEntry("doc.txt");
jos.putNextEntry(entry);
jos.closeEntry(); // Empty jar File Archived (Java) warning issued here
}
catch (IOException e) {
e.printStackTrace();
}
try (ZipOutputStream jos = new ZipOutputStream(new FileOutputStream(new File("archive.jar")))) {
ZipEntry entry = new ZipEntry("doc.txt");
jos.putNextEntry(entry);
jos.closeEntry(); // Empty zip File Archived (Java) warning issued here
}
catch (IOException e) {
e.printStackTrace();
}
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File("archive.jar")));
FileInputStream fis = new FileInputStream(new File("test.txt"))) {
ZipEntry entry = new ZipEntry("doc.txt");
jos.putNextEntry(entry);
byte[] buf = new byte[1024];
int len;
while((len = fis.read(buf)) > 0)
jos.write(buf, 0, len);
jos.closeEntry();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
Check if, for instance, empty entries are added to a jar or zip archive.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.