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

Wrong unmarshal of Domain in EntityType #9

Open
cruncher64 opened this issue Oct 31, 2023 · 5 comments
Open

Wrong unmarshal of Domain in EntityType #9

cruncher64 opened this issue Oct 31, 2023 · 5 comments

Comments

@cruncher64
Copy link

Following issue is observable when EntityTypes with domains not equal to PlatformDomain: The unmarhalled domain will always be PlatformDomain (see c'tor of EntityType), unmarshalled with the numerical value of the other enum class.
Here the test:
ByteBuffer buffer = ByteBuffer.allocate(4096);
try {
// marshal/ unmarshal Domain: correct
Domain d = Domain.inst(MunitionDomain.ANTI_ARMOR);
d.marshal(buffer);
buffer.rewind();
d.unmarshal(buffer);
System.out.println(d.getDescription());
buffer.clear();
// marshal/ unmarshal EntityType incorrect for entity types not equal PlatformDomain
EntityType ent = new EntityType();
ent.setEntityKind(EntityKind.MUNITION).setCountry(Country.GERMANY_DEU).
setDomain(Domain.inst(MunitionDomain.ANTI_ARMOR)).setCategory(1).
setSubCategory(1).setSpecific(3);
ent.marshal(buffer);
buffer.rewind();
EntityType et = new EntityType();
et.unmarshal(buffer);
System.out.println(et.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
which gives following output:
Anti-Armor
EntityType entityKind:EntityKind 2 MUNITION domain:Air country:Country 78 GERMANY_DEU category:1 subCategory:1 specific:3 extra:0
where the MunitionDomain.ANTI_AIR is now PlatformDomain.AIR as PlatformDomain.unmarshal was called despite having EntityKind.Munition.

@cruncher64
Copy link
Author

Even worse: for values > 5 (e.g. MunitionDomain.ANTI_PERSONNEL), you get a NullPointerException in createPdu in the receiver thread of the DisThreadedNetworkInterface, so one cannot fix the issue in its own code for these cases.

@terry-norbraten
Copy link
Collaborator

@cruncher64 I've done some recent work in the DisThreadedNetworkInterface where I was finding too much data was being transmitted/received. Can you test your code above to see if the NPE was fixed?

@terry-norbraten
Copy link
Collaborator

terry-norbraten commented Nov 12, 2023

@cruncher64 I can certainly reproduce your issue stated above. What is happening is that when you create a new EntityType(), a default PlatformDomain.OTHER is instantiated as a default. We'll have to take a look and see if that's what is intended, or even a best practice, in the source generated code as a default behavior.

@cruncher64
Copy link
Author

Yes in the unmarshal method of EntityType you have to do this:

    entityKind = EntityKind.unmarshalEnum(byteBuffer);
    if (entityKind.equals(EntityKind.MUNITION)) {
        domain = Domain.inst(MunitionDomain.OTHER);
    } else if (entityKind.equals(EntityKind.SUPPLY)) {
        domain = Domain.inst(SupplyDomain.NOT_USED);
    }

then it's fine.

@terry-norbraten terry-norbraten transferred this issue from open-dis/opendis7-java Nov 28, 2023
@brutzman
Copy link
Contributor

SInce issue remains unresolved, for clarity have renamed this test class as edu.nps.moves.dis7.test.Issue09Unresolved.java

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

3 participants