Skip to content

FileStore.getBlockSize() should return the configuration block size #183

Closed

Description

@ogregoire

The following test case fails for some reason.

  @Test
  void test() throws IOException {
    var blockSize = 1 << 12;
    var configuration = Configuration.unix().toBuilder().setBlockSize(blockSize).build();
    var fs = Jimfs.newFileSystem(configuration);
    var path = fs.getPath("/home/test/test.txt");
    var store = Files.getFileStore(path);
    assertThat(store.getBlockSize()).isEqualTo(blockSize);
  }

I'm explicitly setting the block size, but I get an IOException when the test case is run:

java.lang.UnsupportedOperationException
        at java.base/java.nio.file.FileStore.getBlockSize(FileStore.java:158)
        ...

I would expect the store to return the block size instead.

Activity

  1. added
    type=defect
    on Feb 22, 2022
  2. ogregoire commented on Mar 31, 2022

    @ogregoire
    Author

    I noticed that the method is new since Java 10. So I guess that a multi-release JAR must be created.

    I worked a bit on it and found that it's possible to create such multi-release jar with the following changes:

    • Copy JimfsFileStore.java to jimfs/src/main/java10/com/google/common/jimfs/.
    • Add the following method at the end of the class:
        @Override
        public long getBlockSize() throws IOException {
          return disk.blockSize();
        }
      
    • Add the following configuration to jimfs/pom.xml:
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <executions>
                <execution>
                  <id>compile-java-7</id>
                  <goals>
                    <goal>compile</goal>
                  </goals>
                  <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                  </configuration>
                </execution>
                <execution>
                  <id>compile-java-10</id>
                  <phase>compile</phase>
                  <goals>
                    <goal>compile</goal>
                  </goals>
                  <configuration>
                    <release>10</release>
                    <compileSourceRoots>
                      <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
                    </compileSourceRoots>
                    <multiReleaseOutput>true</multiReleaseOutput>
                  </configuration>
                </execution>
              </executions>
            </plugin>
      
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.2.0</version>
              <configuration>
                <archive>
                  <manifestEntries>
                    <Multi-Release>true</Multi-Release>
                  </manifestEntries>
                </archive>
              </configuration>
            </plugin>
      

    My only issue was with the tests, hence why I didn't provide a full-blown PR: I don't know how to make tests for a Multi-release project.

  3. added a commit that references this issue on Aug 31, 2026
    9b4b445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4type=defect

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions