Closed koczkatamas closed 6 months ago
With the advent of casting, I believe this problem is solved. Please check if it works now.
The problem is that the
attribute
type referenced fromfield_info
andmethod_info
, but theparent
ofattribute
becomesfield_info
, somethod_info
cannot passthis
as constructor argument.
I was able to reproduce this problem on KSC 0.6 (running on JDK 11) with java_class.ksy
at KSF commit aea1656
dated Jan 19, 2017 (which matches the date this issue was filed):
$ ls -la
total 0
drwxr-xr-x 1 WDAGUtilityAccount 197121 0 Mar 14 20:47 ./
drwxr-xr-x 1 WDAGUtilityAccount 197121 0 Mar 14 20:40 ../
$ curl -fsSLO https://github.com/kaitai-io/kaitai_struct_formats/raw/aea1656b169e8161227f713aba13a9d1f260f08f/executable/java_class.ksy
$ curl -fsSLO https://github.com/kaitai-io/kaitai_struct_compiler/releases/download/0.6/kaitai-struct-compiler-0.6.zip
$ sha256sum kaitai-struct-compiler-0.6.zip
6f4fb84e6d09928e47f1e19c4b4d48d2cc2695db1a8482d3047845ebbaa6113f *kaitai-struct-compiler-0.6.zip
$ unzip -q kaitai-struct-compiler-0.6.zip
$ java -version
java version "11.0.22" 2024-01-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.22+9-LTS-219)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.22+9-LTS-219, mixed mode)
$ kaitai-struct-compiler-0.6/bin/kaitai-struct-compiler --version
kaitai-struct-compiler 0.6
$ kaitai-struct-compiler-0.6/bin/kaitai-struct-compiler --outdir out-ksc0.6 -t java java_class.ksy
$ ls -lR out-ksc0.6/
out-ksc0.6/:
total 0
drwxr-xr-x 1 WDAGUtilityAccount 197121 0 Mar 14 20:50 src/
out-ksc0.6/src:
total 24
-rw-r--r-- 1 WDAGUtilityAccount 197121 20663 Mar 14 20:50 JavaClass.java
$ git -c advice.detachedHead=false clone --depth 1 -b 0.6 -- https://github.com/kaitai-io/kaitai_struct_java_runtime.git runtime-0.6
Cloning into 'runtime-0.6'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 14 (delta 1), reused 8 (delta 0), pack-reused 0
Receiving objects: 100% (14/14), 8.56 KiB | 1.71 MiB/s, done.
Resolving deltas: 100% (1/1), done.
$ find runtime-0.6/ -type f -iname '*.java'
runtime-0.6/src/main/java/io/kaitai/struct/KaitaiStream.java
runtime-0.6/src/main/java/io/kaitai/struct/KaitaiStruct.java
$ javac -version
javac 11.0.22
$ javac -d out-ksc0.6/bin out-ksc0.6/src/JavaClass.java runtime-0.6/src/main/java/io/kaitai/struct/*.java
out-ksc0.6\src\JavaClass.java:446: error: incompatible types: MethodInfo cannot be converted to FieldInfo
this.attributes.add(new Attribute(this._io, this, _root));
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
On KSC 0.7, it is no longer reproducible - the generated JavaClass.java
source file compiles fine with javac
:
kaitai-struct-compiler-0.7
The diff between JavaClass.java
generated by KSC 0.6 and KSC 0.7 looks like this:
out-ksc0.6/src/JavaClass.java
and out-ksc0.7/src/JavaClass.java
Indeed, we can actually see two changes in derived _parent
types:
The _parent
type of Attribute
changed from FieldInfo
to KaitaiStruct
. This fixed the problem in question, because it allows the attribute
type to be used not only from the field_info
type:
field_info:
seq:
# ...
- id: attributes
type: attribute
repeat: expr
repeat-expr: attributes_count
... but also from the method_info
type:
method_info:
seq:
# ...
- id: attributes
type: attribute
repeat: expr
repeat-expr: attributes_count
The _parent
type of ConstantPoolEntry
changed from KaitaiStruct
to JavaClass
- this is correct as well, since the constant_pool_entry
is only used from the top-level seq
, so its _parent
type should be java_class
:
meta:
id: java_class
endian: be
file-extension: class
seq:
# ...
- id: constant_pool
type: constant_pool_entry
repeat: expr
repeat-expr: constant_pool_count - 1
I can confirm that this has not regressed since KSC 0.7 - the same java_class.ksy
is still compiled to valid Java code when using KSC 0.10.
As explained in the previous comment, this issue is resolved.
Compilation of the
executable/java_class.ksy
file fails forcpp_stl
,csharp
andjava
.The problem is that the
attribute
type referenced fromfield_info
andmethod_info
, but theparent
ofattribute
becomesfield_info
, somethod_info
cannot passthis
as constructor argument.