Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8241882

(zipfs) SeekableByteChannel::position does not return the correct value when pos> file size

    Details

    • Type: Bug
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      @Test(dataProvider = "zipfsMap")
          public void zipPositionTest(final Map<String, String> env,
                                      final int compression) throws Exception {
              Path zipFile = generatePath(HERE, "test", ".zip");
              Files.deleteIfExists(zipFile);
              Entry e0 = Entry.of("Entry-0", compression, THE_SLAMS);
              zip(zipFile, env, e0);
              try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env);
                   SeekableByteChannel sbc =
                           Files.newByteChannel(zipfs.getPath(e0.name), Set.of(READ))) {
                  int fSize = (int) sbc.size();
                  System.out.printf("file size= %s%n", fSize);
                  for(var i = 0; i < fSize; i++) {
                      long pos = RANDOM.nextInt(fSize + 10);
                      sbc.position(pos);
                      System.out.printf("i=%s, pos=%s, sbc.pos=%s%n", i, pos, sbc.position());
                      assertEquals(sbc.position(), pos);
                  }

      Output is as follows:

      ----------------
      file size= 69
      i=0, pos=29, sbc.pos=29
      i=1, pos=52, sbc.pos=52
      i=2, pos=19, sbc.pos=19
      i=3, pos=54, sbc.pos=54
      i=4, pos=49, sbc.pos=49
      i=5, pos=24, sbc.pos=24
      i=6, pos=32, sbc.pos=32
      i=7, pos=26, sbc.pos=26
      i=8, pos=19, sbc.pos=19
      i=9, pos=59, sbc.pos=59
      i=10, pos=28, sbc.pos=28
      i=11, pos=43, sbc.pos=43
      i=12, pos=71, sbc.pos=69



      java.lang.AssertionError: expected [71] but found [69]
      Expected :71
      Actual :69
      ----------------

        Attachments

          Activity

            People

            • Assignee:
              lancea Lance Andersen
              Reporter:
              lancea Lance Andersen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: