jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

DOMInputCapsule.readIntSavableMap does not check exceptions

Open tohidemyname opened this issue 2 years ago • 2 comments

The code is as follows:

public IntMap<? extends Savable> readIntSavableMap(String name, IntMap<? extends Savable> defVal) throws IOException {
...

                                if (n instanceof Element && n.getNodeName().equals("MapEntry")) {
                                        Element elem = (Element) n;
                                        currentElem = elem;
                                        int key = Integer.parseInt(currentElem.getAttribute("key"));
                                        Savable val = readSavable("Savable", null);
                                        ret.put(key, val);
                                }                  
         ...
    }

Here Integer.parseInt(currentElem.getAttribute("key")) can throw NumberFormatException. The other methods of this class catch and rethrow IOException. An example is as follows:

public byte[] readByteArray(String name, byte[] defVal) throws IOException {
  try {...
      for (int i = 0; i < strings.length; i++) {
              tmp[i] = Byte.parseByte(strings[i]);
       }...
  }catch (IOException ioe) {
            throw ioe;
        } catch (NumberFormatException nfe) {

            IOException io = new IOException(nfe.toString());
            io.initCause(nfe);
            throw io;

        } catch (DOMException de) {
            IOException io = new IOException(de.toString());
            io.initCause(de);
            throw io;
        }
    }

tohidemyname avatar Jun 27 '23 01:06 tohidemyname

Thanks for bringing this inconsistency to our attention. Would you be interested in authoring a pull request to solve this issue?

stephengold avatar Jul 24 '23 15:07 stephengold

Here is the pull request:https://github.com/jMonkeyEngine/jmonkeyengine/pull/2052 Thx a lot.

tohidemyname avatar Jul 28 '23 02:07 tohidemyname