{"action":"closed","issue":{"url":"https://api.github.com/repos/jankotek/MapDB/issues/502","labels_url":"https://api.github.com/repos/jankotek/MapDB/issues/502/labels{/name}","comments_url":"https://api.github.com/repos/jankotek/MapDB/issues/502/comments","events_url":"https://api.github.com/repos/jankotek/MapDB/issues/502/events","html_url":"https://github.com/jankotek/MapDB/issues/502","id":72544627,"number":502,"title":"FileChannelVol.tryAvailable(long) does not test if storage is available (1.0.7)","user":{"login":"simon-greatrix","id":10000910,"avatar_url":"https://avatars.githubusercontent.com/u/10000910?v=3","gravatar_id":"","url":"https://api.github.com/users/simon-greatrix","html_url":"https://github.com/simon-greatrix","followers_url":"https://api.github.com/users/simon-greatrix/followers","following_url":"https://api.github.com/users/simon-greatrix/following{/other_user}","gists_url":"https://api.github.com/users/simon-greatrix/gists{/gist_id}","starred_url":"https://api.github.com/users/simon-greatrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simon-greatrix/subscriptions","organizations_url":"https://api.github.com/users/simon-greatrix/orgs","repos_url":"https://api.github.com/users/simon-greatrix/repos","events_url":"https://api.github.com/users/simon-greatrix/events{/privacy}","received_events_url":"https://api.github.com/users/simon-greatrix/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jankotek/MapDB/labels/2.0","name":"2.0","color":"009800"},{"url":"https://api.github.com/repos/jankotek/MapDB/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-01T23:14:25Z","updated_at":"2015-05-02T20:34:37Z","closed_at":"2015-05-02T20:34:37Z","body":"The existing `tryAvailable` method looks like this:\r\n\r\n```java\r\n        @Override\r\n        public boolean tryAvailable(long offset) {\r\n            if(hasLimit && offset>sizeLimit) return false;\r\n            if(offset% chunkSize !=0)\r\n                offset += chunkSize - offset% chunkSize; //round up to multiply of chunk size\r\n\r\n            if(offset>size)synchronized (growLock){\r\n                try {\r\n                    channel.truncate(offset);\r\n                    size = offset;\r\n                } catch (IOException e) {\r\n                    throw new IOError(e);\r\n                }\r\n            }\r\n            return true;\r\n        }\r\n```\r\n\r\nThe `FileChannel.truncate` method does not grow the file if the new size is larger than the current size. As far as I can tell the call to truncate above will never do anything and does not fulfill the methods contract to test if the storage will be available.\r\n\r\nI believe that:\r\n\r\n`channel.truncate(offset)`\r\n\r\nshould be replaced with\r\n\r\n`raf.setLength(offset)`\r\n\r\n\r\nFor reference, the JavaDoc:\r\n\r\nhttps://docs.oracle.com/javase/7/docs/api/java/io/RandomAccessFile.html#setLength(long)\r\n\r\nhttps://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#truncate(long)"}}