-
Notifications
You must be signed in to change notification settings - Fork 325
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
Protect NPE in CMRI connection preferences #2734
Changes from all commits
a40b2c9
1acdaab
63fd56f
345f929
bcc1efa
1100222
2332728
469e09d
222d49c
a18da70
e700c98
3e5c3eb
ec5d0e1
728fb68
2a299d4
a44ed8e
2dd633f
d65fbb8
62e5dca
c272052
c4a40b8
31b3005
b0da2de
6a433ff
f780a5b
a7f85ee
94100ef
f2770dc
305c08c
aa2dfab
6f51bba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,33 +52,35 @@ protected void getInstance(Object object) { | |
// though it would be good to fix it if you're working in this area | ||
protected void extendElement(Element e) { | ||
SerialTrafficController tc = ((CMRISystemConnectionMemo)adapter.getSystemConnectionMemo()).getTrafficController(); | ||
SerialNode node = (SerialNode) tc.getNode(0); | ||
int index = 1; | ||
while (node != null) { | ||
// add node as an element | ||
Element n = new Element("node"); | ||
n.setAttribute("name", "" + node.getNodeAddress()); | ||
e.addContent(n); | ||
// add parameters to the node as needed | ||
n.addContent(makeParameter("nodetype", "" + node.getNodeType())); | ||
n.addContent(makeParameter("bitspercard", "" + node.getNumBitsPerCard())); | ||
n.addContent(makeParameter("transmissiondelay", "" + node.getTransmissionDelay())); | ||
n.addContent(makeParameter("num2lsearchlights", "" + node.getNum2LSearchLights())); | ||
n.addContent(makeParameter("pulsewidth", "" + node.getPulseWidth())); | ||
String value = ""; | ||
for (int i = 0; i < node.getLocSearchLightBits().length; i++) { | ||
value = value + Integer.toHexString(node.getLocSearchLightBits()[i] & 0xF); | ||
if (tc != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that if this code runs with tc==null, you're going to store without the node definitions, thereby losing the node definitions. Is that really what you want? |
||
SerialNode node = (SerialNode) tc.getNode(0); | ||
int index = 1; | ||
while (node != null) { | ||
// add node as an element | ||
Element n = new Element("node"); | ||
n.setAttribute("name", "" + node.getNodeAddress()); | ||
e.addContent(n); | ||
// add parameters to the node as needed | ||
n.addContent(makeParameter("nodetype", "" + node.getNodeType())); | ||
n.addContent(makeParameter("bitspercard", "" + node.getNumBitsPerCard())); | ||
n.addContent(makeParameter("transmissiondelay", "" + node.getTransmissionDelay())); | ||
n.addContent(makeParameter("num2lsearchlights", "" + node.getNum2LSearchLights())); | ||
n.addContent(makeParameter("pulsewidth", "" + node.getPulseWidth())); | ||
String value = ""; | ||
for (int i = 0; i < node.getLocSearchLightBits().length; i++) { | ||
value = value + Integer.toHexString(node.getLocSearchLightBits()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("locsearchlightbits", "" + value)); | ||
value = ""; | ||
for (int i = 0; i < node.getCardTypeLocation().length; i++) { | ||
value = value + Integer.toHexString(node.getCardTypeLocation()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("cardtypelocation", "" + value)); | ||
|
||
// look for the next node | ||
node = (SerialNode) tc.getNode(index); | ||
index++; | ||
} | ||
n.addContent(makeParameter("locsearchlightbits", "" + value)); | ||
value = ""; | ||
for (int i = 0; i < node.getCardTypeLocation().length; i++) { | ||
value = value + Integer.toHexString(node.getCardTypeLocation()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("cardtypelocation", "" + value)); | ||
|
||
// look for the next node | ||
node = (SerialNode) tc.getNode(index); | ||
index++; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,33 +37,35 @@ public ConnectionConfigXml() { | |
// though it would be good to fix it if you're working in this area | ||
protected void extendElement(Element e) { | ||
SerialTrafficController tc = ((CMRISystemConnectionMemo)adapter.getSystemConnectionMemo()).getTrafficController(); | ||
SerialNode node = (SerialNode) tc.getNode(0); | ||
int index = 1; | ||
while (node != null) { | ||
// add node as an element | ||
Element n = new Element("node"); | ||
n.setAttribute("name", "" + node.getNodeAddress()); | ||
e.addContent(n); | ||
// add parameters to the node as needed | ||
n.addContent(makeParameter("nodetype", "" + node.getNodeType())); | ||
n.addContent(makeParameter("bitspercard", "" + node.getNumBitsPerCard())); | ||
n.addContent(makeParameter("transmissiondelay", "" + node.getTransmissionDelay())); | ||
n.addContent(makeParameter("num2lsearchlights", "" + node.getNum2LSearchLights())); | ||
n.addContent(makeParameter("pulsewidth", "" + node.getPulseWidth())); | ||
String value = ""; | ||
for (int i = 0; i < node.getLocSearchLightBits().length; i++) { | ||
value = value + Integer.toHexString(node.getLocSearchLightBits()[i] & 0xF); | ||
if (tc != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comment on this commit, I think this will write a configuration file that doesn't contain, hence loses for all time, the node information. |
||
SerialNode node = (SerialNode) tc.getNode(0); | ||
int index = 1; | ||
while (node != null) { | ||
// add node as an element | ||
Element n = new Element("node"); | ||
n.setAttribute("name", "" + node.getNodeAddress()); | ||
e.addContent(n); | ||
// add parameters to the node as needed | ||
n.addContent(makeParameter("nodetype", "" + node.getNodeType())); | ||
n.addContent(makeParameter("bitspercard", "" + node.getNumBitsPerCard())); | ||
n.addContent(makeParameter("transmissiondelay", "" + node.getTransmissionDelay())); | ||
n.addContent(makeParameter("num2lsearchlights", "" + node.getNum2LSearchLights())); | ||
n.addContent(makeParameter("pulsewidth", "" + node.getPulseWidth())); | ||
String value = ""; | ||
for (int i = 0; i < node.getLocSearchLightBits().length; i++) { | ||
value = value + Integer.toHexString(node.getLocSearchLightBits()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("locsearchlightbits", "" + value)); | ||
value = ""; | ||
for (int i = 0; i < node.getCardTypeLocation().length; i++) { | ||
value = value + Integer.toHexString(node.getCardTypeLocation()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("cardtypelocation", "" + value)); | ||
|
||
// look for the next node | ||
node = (SerialNode) tc.getNode(index); | ||
index++; | ||
} | ||
n.addContent(makeParameter("locsearchlightbits", "" + value)); | ||
value = ""; | ||
for (int i = 0; i < node.getCardTypeLocation().length; i++) { | ||
value = value + Integer.toHexString(node.getCardTypeLocation()[i] & 0xF); | ||
} | ||
n.addContent(makeParameter("cardtypelocation", "" + value)); | ||
|
||
// look for the next node | ||
node = (SerialNode) tc.getNode(index); | ||
index++; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this runs with adapter==null, it won't crash right away, but it will behave oddly later on (because the listener won't be present). I'm much rather see a Large Amount of information being logged here so we have some chance of tracking down the real problem, which is the null adapter value.