Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexer: improve logging for empty .class/.jar files #3486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ public ClassFileReader(byte[] classFileBytes, char[] fileName, boolean fullyInit
// by index are tweaked to have their value in inst vars, this minor cost at read-time makes
// all subsequent uses of the constant pool element faster.
super(classFileBytes, null, 0);
if (classFileBytes == null || classFileBytes.length == 0) {
throw new ClassFormatException(ClassFormatException.ErrBadMagic);
}

this.classFileName = fileName;
int readOffset = 10;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
Expand Down Expand Up @@ -285,8 +283,9 @@ public boolean execute(IProgressMonitor progressMonitor) {
}
} catch (IOException | ZipError e) {
if (e instanceof NoSuchFileException) {
IStatus info = new Status(IStatus.INFO, JavaCore.PLUGIN_ID, "File no longer exists: " + this.containerPath, e); //$NON-NLS-1$
org.eclipse.jdt.internal.core.util.Util.log(info);
org.eclipse.jdt.internal.core.util.Util.log(Status.info("Can not index not existing zip " + this.containerPath)); //$NON-NLS-1$
} else if ("zip file is empty".equals(e.getMessage())) { //$NON-NLS-1$
org.eclipse.jdt.internal.core.util.Util.log(Status.info("Can not index empty zip " + this.containerPath)); //$NON-NLS-1$
} else {
org.eclipse.jdt.internal.core.util.Util.log(e, "Failed to index " + this.containerPath); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,11 @@ public void indexDocument() {
// logging the entry that could not be indexed and continue with the next one
// we remove all entries relative to the boggus document
this.document.removeAllIndexEntries();
if (e instanceof ClassFormatException cfe && cfe.getErrorCode() == ClassFormatException.ErrBadMagic) {
Util.log(new Status(IStatus.INFO, JavaCore.PLUGIN_ID,
"Could not index empty " + this.document.getPath())); //$NON-NLS-1$
return;
}
Util.log(new Status(IStatus.WARNING,
JavaCore.PLUGIN_ID,
"The Java indexing could not index " + this.document.getPath() + ". This .class file doesn't follow the class file format specification. Please report this issue against the .class file vendor", //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Loading