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

Alan Bateman Alan.Bateman at oracle.com
Tue Jun 4 18:45:36 UTC 2019


On 04/06/2019 19:31, Karan Mehta wrote:
> Thanks for your quick response. Appreciate it.
>
> The link for man page seems a bit contradictory. At the top, it says, 
> "lseek() allows the file offset to be set beyond the end of the file 
> (but this does not change the size of the file)." but it is followed 
> by the text you mentioned.
> The function declaration is `off_t lseek(int fd, off_t offset, int 
> whence);` where the offset is defined with off_t type. I was trying to 
> reason its size based on stackoverflow here 
> <https://stackoverflow.com/questions/9073667/where-to-find-the-complete-definition-of-off-t-type>. 
> The link 
> <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html#tag_13_67> suggests 
> that they would be signed integers and hence this is a potential 
> overflow and might result in negative value, causing it to be a reason 
> for exception. Should the JNI call be using this 
> <https://stackoverflow.com/a/14351239/4428999> instead since the Java 
> interface offers the option to pass long variable for the offset.
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.

> What should be the correct fix here? Of course, if the underlying OS 
> is 32 bit, even the SO link above won't help but it would make it work 
> on almost all modern hardware.
>
The IOException is correct, it's just the "Illegal argument" from the 
syscall is confusing.

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


More information about the nio-dev mailing list