Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3329: javalib MappedByteBufferImpl no longer calls FileChannel truncate method #3345

Merged

Conversation

LeeTibbert
Copy link
Contributor

@LeeTibbert LeeTibbert commented Jun 22, 2023

Fix #3329

Credit:

Aly on Scala Native Discourse gave invaluable information on how Windows extends files.
Any defects from misinterpretation of that information fall on this Author.

Changes

javalib MappedByteBufferImpl no longer calls FileChannel#truncate to extend files.
The latter method is defined as never extending a file, so the former method calling
the latter was a defect.

This is primarily an internal re-organization which prepares the ground for correcting the more
visible and impactful Issue #3330.

A keen user may detect three user visible changes.

  • argument checking is more extensive and stricter.
  • Message of an IllegalArgumentException was changed to match (a, not every) JVM.
  • Thanks to Aly, the performance of extending a file on Windows should be significantly improved.

@LeeTibbert LeeTibbert added component:javalib os:macos os:linux backport candidate PR which might be backported into previous major release of SN labels Jun 22, 2023
Comment on lines +313 to +319
val channel = FileChannel.open(
f,
StandardOpenOption.READ,
StandardOpenOption.WRITE
)

try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use Using to manage the resource here rather than try, finally. https://www.scala-lang.org/api/2.13.6/scala/util/Using$.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eric,
Thank you for the suggestion. This code needs to also run on Scala 2.12.n.
I believe that Using is not available for that Scala version. `Tis a pity,
the Using idiom is much closer to the Java try-with-resources idiom.
Did I miss something in Scala 2.12?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is added in Scala Collection Compat but I don't think we want to add that. - https://github.com/scala/scala-collection-compat/tree/main/compat/src/main/scala-2.12/scala/util :-(

@WojciechMazur WojciechMazur merged commit 4687be0 into scala-native:main Jun 29, 2023
77 checks passed
WojciechMazur added a commit to WojciechMazur/scala-native that referenced this pull request Sep 1, 2023
…ileChannel truncate method (scala-native#3345)

* Fix scala-native#3329: javalib MappedByteBufferImpl no longer calls truncate method

* Change Exception message to match a JVM

(cherry picked from commit 4687be0)
WojciechMazur added a commit that referenced this pull request Sep 4, 2023
…runcate method (#3345)

* Fix #3329: javalib MappedByteBufferImpl no longer calls truncate method

* Change Exception message to match a JVM

(cherry picked from commit 4687be0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport candidate PR which might be backported into previous major release of SN component:javalib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

javalib MappedByteBuffer uses FileChannel.truncate() to increase file sizes.
3 participants