Class BinaryStubDataTest

java.lang.Object
org.checkerframework.framework.stub.BinaryStubDataTest

public class BinaryStubDataTest extends Object
Tests that a damaged binary stub file is reported as a malformed file, not as a crash.

AnnotationFileElementTypes.loadBinaryStubData turns an IOException into a fallback to text parsing, and anything else into "please report a Checker Framework bug". A corrupt file -- a truncated download, a bad transfer, a bit flip -- must therefore surface as an IOException. That is the whole reason BinaryStubData.readCount and readStringIndex exist, so each is exercised here with the input it is meant to reject: a count that cannot be a real count, and an index that points outside the string pool.

The files are hand-built rather than produced by the writer and then damaged: the point is to reject bytes the writer would never emit, and building them directly says exactly which byte is wrong.

  • Constructor Details

    • BinaryStubDataTest

      public BinaryStubDataTest()
  • Method Details

    • negativeCountIsMalformed

      public void negativeCountIsMalformed() throws IOException
      A negative count must be rejected, not passed to new String[-1].
      Throws:
      IOException
    • hugeCountIsMalformed

      public void hugeCountIsMalformed() throws IOException
      An absurdly large count must be rejected, not allocated.
      Throws:
      IOException
    • stringPoolIndexOutsideThePoolIsMalformed

      public void stringPoolIndexOutsideThePoolIsMalformed() throws IOException
      A string-pool index that points outside the pool must be rejected while the file is read.

      The bad index here is a field name, and every other byte of the file is valid. That is the case that matters: a field's name index is not dereferenced while reading (unlike a class's, which indexes classes immediately), but only later, when the class's records are applied -- outside any IOException handler. Left unvalidated, this file parses successfully, is cached, and then throws ArrayIndexOutOfBoundsException the first time the class is used, crashing the compilation.

      Throws:
      IOException
    • annotationPoolIndexOutsideThePoolIsMalformed

      public void annotationPoolIndexOutsideThePoolIsMalformed() throws IOException
      An annotation-pool index that points outside the pool must be rejected while the file is read.

      Similar to string pool indices, an annotation index is only dereferenced later during application. Left unvalidated, an out-of-bounds index throws ArrayIndexOutOfBoundsException later on, crashing the compiler.

      Throws:
      IOException
    • truncatedFileIsMalformed

      public void truncatedFileIsMalformed() throws IOException
      A file that stops in the middle of a record must be rejected.
      Throws:
      IOException
    • wrongMagicIsMalformed

      public void wrongMagicIsMalformed() throws IOException
      A file that is not a binary stub file at all must be rejected.
      Throws:
      IOException
    • wrongVersionIsMalformed

      public void wrongVersionIsMalformed() throws IOException
      A file written by a different version of the format must be rejected.
      Throws:
      IOException