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

Avoid creating FileInputStream and FileOutputStream for obtaining FileChannel #8078

Closed
leventov opened this issue Jun 28, 2018 · 2 comments · Fixed by #8110
Closed

Avoid creating FileInputStream and FileOutputStream for obtaining FileChannel #8078

leventov opened this issue Jun 28, 2018 · 2 comments · Fixed by #8110

Comments

@leventov
Copy link

There are multiple places in the production code of the project, e. g. in ChunkedNioFile, where FileInputStream or FileOutputStream are created solely to obtain a FileChannel from them. Until Netty projects bumps the compatibility level to Java 7 (where FileChannel.open() methods were added), it's better to obtain a FileChannel by means of creating a RandomAccessFile, because the latter doesn't override Object.finalize(). Also, I would extract those pieces of code into a utility methods like openChannelForRead(File) and openChannelForWrite(File).

@re-thc
Copy link

re-thc commented Jun 29, 2018

Same goes for BufferedReader instances - same finalize problem. It's used in DNS and some other modules.

normanmaurer added a commit that referenced this issue Jul 9, 2018
…eChannel

Motivation:

If all we need is the FileChannel we should better use RandomAccessFile as FileInputStream and FileOutputStream use a finalizer.

Modifications:

Replace FileInputStream and FileOutputStream with RandomAccessFile when possible.

Result:

Fixes #8078.
@normanmaurer
Copy link
Member

@leventov good catch... Check #8110

@normanmaurer normanmaurer added this to the 4.1.26.Final milestone Jul 9, 2018
normanmaurer added a commit that referenced this issue Jul 9, 2018
…eChannel

Motivation:

If all we need is the FileChannel we should better use RandomAccessFile as FileInputStream and FileOutputStream use a finalizer.

Modifications:

Replace FileInputStream and FileOutputStream with RandomAccessFile when possible.

Result:

Fixes #8078.
normanmaurer added a commit that referenced this issue Aug 16, 2019
…eChannel

Motivation:

If all we need is the FileChannel we should better use RandomAccessFile as FileInputStream and FileOutputStream use a finalizer.

Modifications:

Replace FileInputStream and FileOutputStream with RandomAccessFile when possible.

Result:

Fixes #8078.
normanmaurer added a commit that referenced this issue Aug 17, 2019
#8110)

Motivation:

If all we need is the FileChannel we should better use RandomAccessFile as FileInputStream and FileOutputStream use a finalizer.

Modifications:

Replace FileInputStream and FileOutputStream with RandomAccessFile when possible.

Result:

Fixes #8078.
@normanmaurer normanmaurer added this to the 4.1.40.Final milestone Aug 17, 2019
normanmaurer added a commit that referenced this issue Aug 17, 2019
#8110)

Motivation:

If all we need is the FileChannel we should better use RandomAccessFile as FileInputStream and FileOutputStream use a finalizer.

Modifications:

Replace FileInputStream and FileOutputStream with RandomAccessFile when possible.

Result:

Fixes #8078.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants