Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open example zip #13

Open
ghost opened this issue Feb 29, 2020 · 1 comment
Open

Cannot open example zip #13

ghost opened this issue Feb 29, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 29, 2020

Built using intelliJ idea maven 3 jdk12

In generated java source there are some cases of error: cannot find symbol this.body._read();

call_stack

generated java code dump

@generalmimon
Copy link
Member

generalmimon commented Mar 1, 2020

Try updating to the latest development compiler version. I can spot a known problem to me in the code which always occurred when using type-switching with user types and disabled autoRead (when _read() is not called automatically from the class constructor).

Here is an example from the linked code:

switch (tag()) {
    case 1: {
        this._raw_body = this._io.readBytes(size());
        KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
        this.body = new Attribute1(_io__raw_body, this, _root);
        this.body._read(); // trying to access <Object>._read()! 
        break;
    }
    default: {
        this.body = this._io.readBytes(size());
        break;
    }
}

Because KaitaiStruct and byte[] are incompatible types, the property is declared few lines below as private Object body;.

The core of the issue is that the combined type of the switch does not contain the method _read() because it is "polluted" with unrelated types from other cases (e.g. byte[], String, int etc.) Despite that we know in the particular switch branch that calling _read does make sense, the Java compile-time type checking engine does not and we have to cast it before.

But it should be fixed now since commit kaitai-io/kaitai_struct_compiler@872f8c2, so please check it out. The issue is described in kaitai-io/kaitai_struct#204 and the related test is called DebugSwitchUser (but as I can see in the generated DebugSwitchUser.java:129, the combined type there is KaitaiStruct, not Object, so it could be faked with no casting but adding _read() as abstract method to KaitaiStruct - so it's not testing the worst case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant