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

(zipfs) SeekableByteChannel::size does not return the correct value when the file is open for writing and no updates are made to the file

    Details

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

      Description

      The following test will fail:

          @Test(dataProvider = "zipfsMap")
          public void zipSizeTest(final Map<String, String> env,
                                  final int compression) throws Exception {
              Path osFile = Path.of("GrandSlams.txt");
              Files.deleteIfExists(osFile);
              Files.writeString(osFile, THE_SLAMS);
              Entry e0 = Entry.of("Entry-0", compression, THE_SLAMS);
              Path zipFile = generatePath(HERE, "test", ".zip");
              Files.deleteIfExists(zipFile);
              zip(zipFile,env, e0);

              try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env);
                   SeekableByteChannel sch = Files.newByteChannel(zipfs.getPath(e0.name), Set.of(READ, WRITE))) {
                  System.out.printf("File size=%s, channel size=%s %n", THE_SLAMS.length(), sch.size());
                  assertEquals(sch.size(), THE_SLAMS.length());
              }
              try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env);
                   SeekableByteChannel sch = Files.newByteChannel(zipfs.getPath(e0.name), Set.of(WRITE))) {
                  System.out.printf("File size=%s, channel size=%s %n", THE_SLAMS.length(), sch.size());
                  assertEquals(sch.size(), THE_SLAMS.length());
              }
              try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env);
                   SeekableByteChannel sch = Files.newByteChannel(zipfs.getPath(e0.name), Set.of(APPEND))) {
                  System.out.printf("File size=%s, channel size=%s %n", THE_SLAMS.length(), sch.size());
                  assertEquals(sch.size(), THE_SLAMS.length());
              }
              Files.deleteIfExists(zipFile);
          }

      The error is:

      ------------------
      java.lang.AssertionError: expected [69] but found [0]
      Expected :69
      Actual :0
      <Click to see difference>


      at org.testng.Assert.fail(Assert.java:96)
      at org.testng.Assert.failNotEquals(Assert.java:776)
      at org.testng.Assert.assertEqualsImpl(Assert.java:137)
      at org.testng.Assert.assertEquals(Assert.java:118)
      at org.testng.Assert.assertEquals(Assert.java:547)
      at org.testng.Assert.assertEquals(Assert.java:557)
      at test.FailingChannelTests.zipSizeTest(FailingChannelTests.java:135)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
      at org.testng.TestRunner.privateRun(TestRunner.java:648)
      at org.testng.TestRunner.run(TestRunner.java:505)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
      at org.testng.SuiteRunner.run(SuiteRunner.java:364)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
      at org.testng.TestNG.runSuites(TestNG.java:1049)
      at org.testng.TestNG.run(TestNG.java:1017)
      at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
      at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)

      ------------------

        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: