Skip to content

Commit f076644

Browse files
markbastianvedang
authored andcommitted
Add type hints to breaking changes in java.nio.ByteBuffer
Fixes Java 13+ compatiblity issues, as noted in clj-commons#23. Copying the relevant parts from the Issue: `java.nio.ByteBuffer` and the other buffer types in `java.nio` now define absolute bulk `get` and `put` methods to transfer contiguous sequences of bytes without regard to or effect on the buffer position. Due to this, running durable-queue against Java 13+ leads to the following error: No matching method put found taking 2 args for class `java.nio.DirectByteBuffer` This commit fixes the problem by adding the relevant type-hints Author: Mark Bastian Ref: https://github.com/markbastian/durable-queue Closes: clj-commons#23 Closes: clj-commons#24
1 parent c924ecc commit f076644

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ pom.xml.asc
99
/.nrepl-port
1010
.DS_Store
1111
/doc
12-
push
12+
push
13+
*.iml
14+
.idea/

src/durable_queue.clj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@
174174
(with-buffer [buf slab]
175175
(reset! status s)
176176
(.put buf (p/+ offset 1)
177-
(case s
178-
:incomplete 0
179-
:in-progress 1
180-
:complete 2))
177+
(byte
178+
(case s
179+
:incomplete 0
180+
:in-progress 1
181+
:complete 2)))
181182
(invalidate slab (p/+ offset 1) 1)
182183
nil)))
183184

@@ -190,9 +191,9 @@
190191
(fn []
191192
(with-buffer [buf slab]
192193
(let [^ByteBuffer buf (-> buf
193-
(.position offset)
194+
(.position ^Long offset)
194195
^ByteBuffer
195-
(.limit (+ offset len))
196+
(.limit ^Long (+ offset len))
196197
.slice)
197198
checksum' (.getLong buf 2)
198199
ary (bs/to-byte-array (.position buf header-size))]
@@ -303,17 +304,17 @@
303304
(let [ary (nippy/freeze descriptor)
304305
cnt (count ary)
305306
pos @position
306-
^ByteBuffer buf (.position buf pos)]
307+
^ByteBuffer buf (.position buf ^Long pos)]
307308

308309
(when (> (.remaining buf) (+ (count ary) header-size))
309310
;; write to the buffer
310311
(doto buf
311-
(.position pos)
312+
(.position ^Long pos)
312313
(.put (byte 1)) ;; exists
313314
(.put (byte 0)) ;; incomplete
314315
(.putLong (checksum cnt ary))
315316
(.putInt cnt)
316-
(.put ary)
317+
(.put ^bytes ary)
317318
(.put (byte 0))) ;; next doesn't exist
318319

319320
(swap! position + header-size cnt)

0 commit comments

Comments
 (0)