-
Notifications
You must be signed in to change notification settings - Fork 10
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
Comments
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. |
@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? |
@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. |
Yes in the unmarshal method of EntityType you have to do this:
then it's fine. |
SInce issue remains unresolved, for clarity have renamed this test class as edu.nps.moves.dis7.test.Issue09Unresolved.java |
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.
The text was updated successfully, but these errors were encountered: