There is a sorting problem in the ROSBridgeClient's typeMatch function
78226415 opened this issue · 0 comments
Hi,
The typeMatch function is :
public void typeMatch(TypeDef t, Class<? extends Message> c) throws InterruptedException {
if (c == null)
throw new RuntimeException("No registered message type found for: " + t.type);
Field[] fields = c.getFields();
for (int i = 0; i < t.fieldnames.length; i++) {
The array of 'fields' is arranged in alphabetical order, but, Perhaps the array of 't.fieldnames' is not. So there maybe an error when you run the code. You may see the problem in a test case: http://xxhong.net/2016/12/01/ros-client/#comments
you may have some language problem because it is written by Chinese.
There maybe a method to help solving this problem by adding sorting code about array like :
public void typeMatch(TypeDef t, Class<? extends Message> c) throws InterruptedException {
if (c == null)
throw new RuntimeException("No registered message type found for: " + t.type);
Field[] fields = c.getFields();
/******sorting t, include fields:fieldnames、examples、fieldarraylen、fieldtypes******/
String[] tempFieldNames = new String[t.fieldnames.length];
String[] tempExamples = new String[t.fieldnames.length];
int[] tempFieldArrayLen = new int[t.fieldnames.length];
String[] tempFieldTypes = new String[t.fieldnames.length];
for (int i = 0; i < t.fieldnames.length; i++) {
tempFieldNames[i] = t.fieldnames[i];
tempExamples[i] = t.examples[i];
tempFieldArrayLen[i] = t.fieldarraylen[i];
tempFieldTypes[i] = t.fieldtypes[i];
}
Arrays.sort(t.fieldnames);
t.examples = new String[t.fieldnames.length];
t.fieldtypes = new String[t.fieldnames.length];
t.fieldarraylen = new int[t.fieldnames.length];
for (int i = 0; i < t.fieldnames.length; i++) {
int oldIndex = 0;
for (int k = 0; k < tempFieldNames.length; k++) {
if(t.fieldnames[i].equals(tempFieldNames[k])){
oldIndex = k;
break;
}
}
t.examples[i] = tempExamples[oldIndex];
t.fieldtypes[i] = tempFieldTypes[oldIndex];
t.fieldarraylen[i] = tempFieldArrayLen[oldIndex];
}
/****************************************************************************************************/
for (int i = 0; i < t.fieldnames.length; i++) {
Maybe there should be other method to solve this problem.
Thanks