From 8fe399b8718b1a25055f18b61707ca0cf03112f0 Mon Sep 17 00:00:00 2001
From: Shreyas C S <shreyascs012@gmail.com>
Date: Fri, 20 Sep 2024 06:43:31 +0530
Subject: [PATCH] fixed StringCharBuffer (#498)

---
 .../modules/java.base/java/nio/ByteBuffer.java   |  8 ++++++++
 .../modules/java.base/java/nio/CharBuffer.java   |  3 +++
 src/tests/CharBufferTest.java                    | 16 ++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 src/tests/CharBufferTest.java

diff --git a/src/classes/modules/java.base/java/nio/ByteBuffer.java b/src/classes/modules/java.base/java/nio/ByteBuffer.java
index f4621fa0..ad3bdfae 100644
--- a/src/classes/modules/java.base/java/nio/ByteBuffer.java
+++ b/src/classes/modules/java.base/java/nio/ByteBuffer.java
@@ -263,6 +263,9 @@ public ByteBuffer putLong(long x) {
 
     return this;
   }
+  public int arrayOffset(){
+    return offset;
+  }
 
   @Override
   public byte[] array() {
@@ -316,4 +319,9 @@ public boolean equals(Object ob) {
   Object base() {
     return array;
   }
+  @Override
+  public final ByteBuffer flip() {
+    super.flip();
+    return this;
+  }
 }
diff --git a/src/classes/modules/java.base/java/nio/CharBuffer.java b/src/classes/modules/java.base/java/nio/CharBuffer.java
index b5714ac2..0bbafacc 100644
--- a/src/classes/modules/java.base/java/nio/CharBuffer.java
+++ b/src/classes/modules/java.base/java/nio/CharBuffer.java
@@ -88,6 +88,9 @@ public static CharBuffer wrap(CharSequence outMess) {
     charBuffer.flip();
     return charBuffer;
   }
+  public int arrayOffset(){
+    return offset;
+  }
 
   @Override
   public char[] array() {
diff --git a/src/tests/CharBufferTest.java b/src/tests/CharBufferTest.java
new file mode 100644
index 00000000..0502442b
--- /dev/null
+++ b/src/tests/CharBufferTest.java
@@ -0,0 +1,16 @@
+import gov.nasa.jpf.util.test.TestJPF;
+import org.junit.Test;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.StandardCharsets;
+
+public class CharBufferTest extends TestJPF {
+    @Test
+    public void Test_Wrap() throws CharacterCodingException {
+        if(verifyNoPropertyViolation()){
+            java.nio.charset.StandardCharsets.UTF_8.newEncoder().encode(java.nio.CharBuffer.wrap("heyo"));
+        }
+    }
+}