beanit / asn1bean

ASN1bean (formerly known as jASN1) is a Java ASN.1 BER and DER encoding/decoding library
https://www.beanit.com/asn1/
Apache License 2.0
110 stars 45 forks source link

asn1bean-compiler generates code that doesn't compile when a field is called 'length' #46

Open morten-holm opened 2 years ago

morten-holm commented 2 years ago

Using the asn1bean-compiler on this asn file generates a .java file that does not compile:

TEST
DEFINITIONS IMPLICIT TAGS       ::=

BEGIN

ContentInfo  ::= SEQUENCE
{
     extensionType      [0] INTEGER,
     length         [1] INTEGER
}

END

It generates this (lines 118-128):

        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
            length = new BerInteger();
            vByteCount += length.decode(is, false);
            if (lengthVal >= 0 && vByteCount == lengthVal) {
                return tlByteCount + vByteCount;
            }
            vByteCount += berTag.decode(is);
        }
        else {
            throw new IOException("Tag does not match mandatory sequence component.");
        }

And the problem is obviously that a BerInteger is assigned to the local length variable of type BerLength. A trivial fix could be adding this.-prefix to class variable assignments.