Skip to content

Commit 574b076

Browse files
author
Fede A
committed
fixes _read_class_data
1 parent 3d0a1a4 commit 574b076

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

javaobj/v2/beans.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ def __init__(self, class_desc_type):
254254
# The super class of this one, if any
255255
self.super_class = None # type: Optional[JavaClassDesc]
256256

257+
# Indicates if it is a super class
258+
self.is_super_class = False
259+
257260
# List of the interfaces of the class
258261
self.interfaces = [] # type: List[str]
259262

@@ -387,6 +390,7 @@ def __init__(self):
387390
self.annotations = (
388391
{}
389392
) # type: Dict[JavaClassDesc, List[ParsedJavaContent]]
393+
self.is_external_instance = False
390394

391395
def __str__(self):
392396
return "[instance 0x{0:x}: type {1}]".format(

javaobj/v2/core.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
ClassDataType,
5252
)
5353
from .stream import DataStreamReader
54+
from .transformers import DefaultObjectTransformer
5455
from ..constants import (
5556
ClassDescFlags,
5657
StreamConstants,
@@ -492,6 +493,10 @@ def _do_object(self, type_code=0):
492493
self._log.debug("Done reading object handle %x", handle)
493494
return instance
494495

496+
def _is_default_supported(self, class_name):
497+
default_transf = [x for x in self.__transformers if isinstance(x, DefaultObjectTransformer)]
498+
return len(default_transf) and class_name in default_transf[0]._type_mapper
499+
495500
def _read_class_data(self, instance):
496501
# type: (JavaInstance) -> None
497502
"""
@@ -508,12 +513,16 @@ def _read_class_data(self, instance):
508513
values = {} # type: Dict[JavaField, Any]
509514
cd.validate()
510515
if cd.data_type == ClassDataType.NOWRCLASS or cd.data_type == ClassDataType.WRCLASS:
511-
if cd.data_type == ClassDataType.NOWRCLASS:
516+
read_custom_data = cd.data_type == ClassDataType.WRCLASS and cd.is_super_class and not self._is_default_supported(cd.name)
517+
if read_custom_data or cd.data_type == ClassDataType.WRCLASS and instance.is_external_instance:
518+
annotations[cd] = self._read_class_annotations(cd)
519+
else:
512520
for field in cd.fields:
513521
values[field] = self._read_field_value(field.type)
514522
all_data[cd] = values
515-
else:
516-
annotations[cd] = self._read_class_annotations(cd)
523+
524+
if cd.data_type == ClassDataType.WRCLASS:
525+
annotations[cd] = self._read_class_annotations(cd)
517526
else:
518527
if cd.data_type == ClassDataType.OBJECT_ANNOTATION:
519528
# Call the transformer if possible

javaobj/v2/transformers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737

3838
# Javaobj
3939
from .api import ObjectTransformer
40-
from .beans import JavaClassDesc, JavaInstance
41-
from .core import JavaStreamParser
42-
from .stream import DataStreamReader
40+
from .beans import JavaInstance
4341
from ..constants import TerminalCode, TypeCode
4442
from ..utils import to_bytes, log_error, log_debug, read_struct, read_string
4543

0 commit comments

Comments
 (0)