Skip to content

Commit d5ee5d9

Browse files
committed
Fixed bugs found by Copilot review
Signed-off-by: Thomas Calmant <thomas.calmant@gmail.com>
1 parent ccb2fae commit d5ee5d9

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

javaobj/v1/beans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def __init__(self, classdesc=None):
199199
self.classdesc = classdesc
200200

201201
def __hash__(self):
202-
return list.__hash__(self)
202+
return object.__hash__(self)
203203

204204

205205
class JavaByteArray(JavaObject):

javaobj/v1/transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __extra_loading__(self, unmarshaller, ident=0):
136136
"""
137137
# Ignore the blockdata opid
138138
(opid,) = unmarshaller._readStruct(">B")
139-
if opid != ClassDescFlags.SC_BLOCK_DATA:
139+
if opid != TerminalCode.TC_BLOCKDATA:
140140
raise ValueError("Start of block data not found")
141141

142142
# Read HashMap fields

javaobj/v1/unmarshaller.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
# Convertion of a Java type char to its NumPy equivalent
8484
NUMPY_TYPE_MAP = {
8585
TypeCode.TYPE_BYTE: "B",
86-
TypeCode.TYPE_CHAR: "b",
86+
TypeCode.TYPE_CHAR: ">u2",
8787
TypeCode.TYPE_DOUBLE: ">d",
8888
TypeCode.TYPE_FLOAT: ">f",
8989
TypeCode.TYPE_INTEGER: ">i",
@@ -508,7 +508,8 @@ def do_object(self, parent=None, ident=0):
508508
# classdata[]
509509

510510
if (
511-
classdesc.flags & ClassDescFlags.SC_EXTERNALIZABLE
511+
classdesc is not None
512+
and classdesc.flags & ClassDescFlags.SC_EXTERNALIZABLE
512513
and not classdesc.flags & ClassDescFlags.SC_BLOCK_DATA
513514
):
514515
# TODO:
@@ -831,8 +832,9 @@ def _oops_dump_state(self, ignore_remaining_data=False):
831832
"(2nd line is an actual position!):"
832833
)
833834

834-
# Do not use a keyword argument
835-
self.object_stream.seek(-16, os.SEEK_CUR)
835+
# Do not use a keyword argument; clamp to avoid seeking before start
836+
current_pos = self.object_stream.tell()
837+
self.object_stream.seek(max(0, current_pos - 16))
836838
position = self.object_stream.tell()
837839
the_rest = self.object_stream.read()
838840

javaobj/v2/transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class NumpyArrayTransformer(ObjectTransformer):
506506
# Convertion of a Java type char to its NumPy equivalent
507507
NUMPY_TYPE_MAP = {
508508
TypeCode.TYPE_BYTE: "B",
509-
TypeCode.TYPE_CHAR: "b",
509+
TypeCode.TYPE_CHAR: ">u2",
510510
TypeCode.TYPE_DOUBLE: ">d",
511511
TypeCode.TYPE_FLOAT: ">f",
512512
TypeCode.TYPE_INTEGER: ">i",

0 commit comments

Comments
 (0)