Where can I find the list of all Java (SE 7) standard library classes which have methods which will throw an EOFException?

StackOverflow https://stackoverflow.com/questions/21458345

Question

I'm trying to track down the source of an EOFException in some client/server code, but many of the classes used only have methods which say that they throw an IOException, not specifically an EOFException. Normally I'd just look at the stack trace but I don't have it and can't reproduce it. So, it would be helpful to have a list of every class which has methods which throw EOFException specifically, but I don't know how to find out this information.

Is there a source of information on every (standard) Java class (in SE 7, in my case) which has methods which throw EOFException? I have tried reading the Javadocs on EOFException to no avail.

(I have found, at least, that DataInput does mentionEOFException. But are there any more?)

Afterword: Since it seems the only way to find out is to inspect the source code, here is the result of me searching for "EOFException" in the extracted source code (1.7.0_45).

Was it helpful?

Solution

EDIT: Added results for 7.51, for all source code in the JDK, at the bottom.

In Java 6.17, here are all classes that explicitly throw java.io.EOFException. Specifically, it is the number of times new\s+EOFException was found in each source-code file.

java.io.DataInputStream.java: 8
java.io.ObjectInputStream.java: 6
java.io.RandomAccessFile.java: 8
java.util.zip.GZIPInputStream.java: 2
java.util.zip.InflaterInputStream.java: 1
java.util.zip.ZipFile.java: 1
java.util.zip.ZipInputStream.java: 1

Here is another bit of information: All source-code files containing catch\s*\(\s*EOFException:

java.io.ObjectInputStream.java: 1
java.util.zip.ZipInputStream.java: 1

Note that there are no standard java.* Exception classes that extend EOFException (there are no occurances of

extends\s+([a-z]+\.)*EOFException

anywhere in the java.* source-code).

This is a limited but valuable starting point. As mentioned by others, there may be situations that this misses--when all you have is the source-code to work from, it will be time-consuming to find them. Hopefully this information will set you down the right path.


Here are the results for Java 7.51, for all source-code provided with the JDK:

extends\s+([a-z]+\.)*EOFException

none

catch\s*\(\s*EOFException

com.sun.imageio.plugins.gif.GIFImageReader: 1
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl: 1
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl: 4
com.sun.org.apache.xerces.internal.impl.XMLVersionDetector: 1
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDLoader: 2
java.io.ObjectInputStream: 1
java.util.zip.ZipInputStream: 1

new\s+EOFException

com.sun.corba.se.impl.io.IIOPInputStream: 1
com.sun.imageio.plugins.png.PNGImageReader: 1
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl: 1
com.sun.org.apache.xerces.internal.impl.XMLEntityManager: 1
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner: 1
java.io.DataInputStream: 8
java.io.ObjectInputStream: 6
java.io.RandomAccessFile: 8
java.util.zip.GZIPInputStream: 2
java.util.zip.InflaterInputStream: 1
java.util.zip.ZipFile: 1
java.util.zip.ZipInputStream: 1
javax.imageio.stream.ImageInputStreamImpl: 8

OTHER TIPS

You can find that out only under the assumption that the code creates and immediately throws an EOFException. But the follwoing could also throw an EOFException:

class Foo {
    ...
    public void iAmHarmless(Exception x) { if (x != null) throw x; }
    ...
 }

Or how about the follwoing, to defeat aliteralminds method:

 class XYException extends EOFException { ... }
 class Foo {
     public void surprise() { throw new XYException().super(); }
 }

Joking aside - methods from many classes may throw EOFException simply because of inheritance. A grep for "EOFException" gives only the very base classes. But you must consider all subclasses thereof. Example: java.util.jar.JarInputStream

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top