jMonkeyEngine / jMonkeyEngine/jmonkeyengine

DOMInputCapsule.readIntSavableMap does not check exceptions

Open
#2,039 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #2052 by @tohidemyname — closed without merging
defect
Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

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;
        }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at DOMInputCapsule.readIntSavableMap and compare its exception handling with the readByteArray example in the issue. Check how malformed MapEntry key values are reported, then verify that NumberFormatException is exposed as an IOException with the original cause while preserving existing IOException behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.