Invalid argument exception when trying to seek FilePosition to LONG.MAX_VALUE

Alan Bateman Alan.Bateman at oracle.com
Wed Jun 5 10:48:19 UTC 2019


On 04/06/2019 21:07, Karan Mehta wrote:
> > The code uses lseek64 and off64_t so I don't think this is the 
> issue. You can verify this by running with strace and you should see 
> output similar to what I had in the first mail.
>
> I ran strace on a 64 bit Linux box but I see calls to only lseek 
> instead of lseek64. Am I missing something here?
It's just an alias for llseek. You should be able to see the value of 
the offset specified to the syscall, it will be 9223372036854775807 when 
you use fc.position(Long.MAX_VALUE).

> What does it show up on mac?
>
> > The IOException is correct, it's just the "Illegal argument" from 
> the syscall is confusing.
>
> Should the IOException be swallowed here according to the FileChannel 
> interface contract and the resulting operation be no-op for the caller 
> instead? Does this mean that any file size longer than INT.MAX_VALUE 
> can potentially cause a problem here, either when trying to read from 
> it or seeking it?
>
I'm not sure what you mean by "swallowing" the exception here. 
FileChannel.position(long) is implemented to use lseek64 and I think is 
failing with values larger than the file system. I don't think 
Integer.MAX_VALUE is an issue.

-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190605/ff690d0e/attachment.html>


More information about the nio-dev mailing list