Skip to content

Commit

Permalink
Fix the remaining ByteBuffer errors (#938)
Browse files Browse the repository at this point in the history
* Perform a more extensive search and fix the remaining ByteBuffer errors to be compatible with Java 8 runtimes

* Minor wording

---------

Co-authored-by: Yan Zhou <[email protected]>
  • Loading branch information
JoeJoe1989 and Yan Zhou authored Sep 28, 2023
1 parent 1da9f81 commit 854dac8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and what APIs have changed, if applicable.

## [Unreleased]

## [29.46.4] - 2023-09-27
- Conduct a more thorough search and fix the remaining ByteBuffer errors to be compatible with Java 8 runtimes.

## [29.46.3] - 2023-09-26
- Fix ByteBuffer errors to be compatible with Java 8 runtimes.

Expand Down Expand Up @@ -5539,7 +5542,8 @@ patch operations can re-use these classes for generating patch messages.

## [0.14.1]

[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.46.3...master
[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.46.4...master
[29.46.4]: https://github.com/linkedin/rest.li/compare/v29.46.3...v29.46.4
[29.46.3]: https://github.com/linkedin/rest.li/compare/v29.46.2...v29.46.3
[29.46.2]: https://github.com/linkedin/rest.li/compare/v29.46.1...v29.46.2
[29.46.1]: https://github.com/linkedin/rest.li/compare/v29.46.0...v29.46.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.schema.UnionDataSchema;
import com.linkedin.data.template.DataTemplateUtil;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.AbstractMap;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -292,7 +293,7 @@ private Object translate(Object value, DataSchema dataSchema, Schema avroSchema)
case BYTES:
ByteBuffer byteBuffer = (ByteBuffer) value;
ByteString byteString = ByteString.copy(byteBuffer);
byteBuffer.rewind();
((Buffer)byteBuffer).rewind();
result = byteString;
break;
case ENUM:
Expand Down
29 changes: 15 additions & 14 deletions data/src/main/java/com/linkedin/data/codec/BufferChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.nio.Buffer;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down Expand Up @@ -261,11 +262,11 @@ public BufferChain position(Position pos)
{
_currentIndex++;
_currentBuffer = _bufferList.get(_currentIndex);
_currentBuffer.position(0);
((Buffer)_currentBuffer).position(0);
}
else
{
_currentBuffer.position(pos._position);
((Buffer)_currentBuffer).position(pos._position);
}
return this;
}
Expand Down Expand Up @@ -424,10 +425,10 @@ public ByteBuffer get(int length)
else
{
buffer = _currentBuffer.slice();
buffer.limit(length);
_currentBuffer.position(_currentBuffer.position() + length);
((Buffer)buffer).limit(length);
((Buffer)_currentBuffer).position(_currentBuffer.position() + length);
}
buffer.flip();
((Buffer)buffer).flip();
return buffer;
}

Expand Down Expand Up @@ -634,7 +635,7 @@ private ArrayList<ByteBuffer> accummulateByteBuffers(ArrayList<ByteBuffer> buffe

ByteBuffer byteBuffer = ByteBuffer.wrap(array, arrayStart, bytesInCurrentBuffer);
byteBuffer.order(_order);
_currentBuffer.position(newPosition);
((Buffer)_currentBuffer).position(newPosition);
if (bufferList == null)
bufferList = new ArrayList<>();
bufferList.add(byteBuffer);
Expand All @@ -653,11 +654,11 @@ else if (bufferList == null)
_decoder.reset();
CharBuffer charBuffer = CharBuffer.allocate(numBytes); // char should be smaller than # of bytes in buffer.
int limit = _currentBuffer.limit();
_currentBuffer.limit(_currentBuffer.position() + numBytes);
((Buffer)_currentBuffer).limit(_currentBuffer.position() + numBytes);
checkCoderResult(_decoder.decode(_currentBuffer, charBuffer, true));
_currentBuffer.limit(limit);
((Buffer)_currentBuffer).limit(limit);
_decoder.flush(charBuffer);
charBuffer.flip();
((Buffer)charBuffer).flip();
result = charBuffer.toString();
}
else
Expand Down Expand Up @@ -947,7 +948,7 @@ public byte[] toBytes()
{
if (_currentBuffer.remaining() > 0)
{
_currentBuffer.limit(_currentBuffer.position());
((Buffer)_currentBuffer).limit(_currentBuffer.position());
}
rewind();
int size = 0;
Expand Down Expand Up @@ -979,7 +980,7 @@ public BufferChain rewind()
for (ByteBuffer buffer : _bufferList)
{
// out.println("limit " + buffer.limit());
buffer.rewind();
((Buffer)buffer).rewind();
// out.println("limit after rewind " + buffer.limit());
}
_currentIndex = 0;
Expand Down Expand Up @@ -1015,7 +1016,7 @@ public BufferChain readFromInputStream(InputStream inputStream) throws IOExcepti
if (bytesRead != -1)
{
int newPosition = _currentBuffer.position() + bytesRead;
_currentBuffer.position(newPosition);
((Buffer)_currentBuffer).position(newPosition);
}
if (bytesRead < remaining)
{
Expand All @@ -1036,7 +1037,7 @@ public BufferChain writeToOutputStream(OutputStream outputStream) throws IOExcep
{
if (_currentBuffer.remaining() > 0)
{
_currentBuffer.limit(_currentBuffer.position());
((Buffer)_currentBuffer).limit(_currentBuffer.position());
}
rewind();
for (ByteBuffer buffer : _bufferList)
Expand Down Expand Up @@ -1235,7 +1236,7 @@ private final ByteBuffer reserve(int size)
{
if (_currentBuffer.remaining() < size)
{
_currentBuffer.limit(_currentBuffer.position());
((Buffer)_currentBuffer).limit(_currentBuffer.position());
_currentBuffer = allocateByteBuffer(size);
_currentIndex++;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=29.46.3
version=29.46.4
group=com.linkedin.pegasus
org.gradle.configureondemand=true
org.gradle.parallel=true
Expand Down

0 comments on commit 854dac8

Please sign in to comment.