Skip to content
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

DOMInputCapsule.readIntSavableMap does not check exceptions #2039

Open
tohidemyname opened this issue Jun 27, 2023 · 2 comments
Open

DOMInputCapsule.readIntSavableMap does not check exceptions #2039

tohidemyname opened this issue Jun 27, 2023 · 2 comments
Labels
defect Something that is supposed to work, but doesn't. Less severe than a "bug"

Comments

@tohidemyname
Copy link

tohidemyname commented Jun 27, 2023

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;
        }
    }
@stephengold
Copy link
Member

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

@stephengold stephengold added the defect Something that is supposed to work, but doesn't. Less severe than a "bug" label Jul 24, 2023
@stephengold stephengold added this to the Future Release milestone Jul 24, 2023
@tohidemyname
Copy link
Author

Here is the pull request:#2052
Thx a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something that is supposed to work, but doesn't. Less severe than a "bug"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants