jMonkeyEngine / jMonkeyEngine/jmonkeyengine

SAXUtil throws inconsistent exceptions when it encounters wrong formats

Open
#1,998 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

SAXUtil throws SAXException when formats are wrong. For example, a method is as follows:

public static int parseInt(String i, int def) throws SAXException{ if (i == null) return def; else{ try { return Integer.parseInt(i); } catch (NumberFormatException ex){ throw new SAXException("Expected an integer, got '"+i+"'"); } } }

The other classes throw IOException. For example, DOMInputCapsule.java has the following code:

public int readInt(String name, int defVal) throws IOException { String tmpString = currentElem.getAttribute(name); if (tmpString == null || tmpString.length() < 1) return defVal; try { return Integer.parseInt(tmpString); } 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; } }

I assume that all wrong formats will throw IOException. As a result, my code fails to catch the exceptions thrown by SAXException.

Can jmonkeyengine fix the problem?

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 with SAXUtil.parseInt and DOMInputCapsule.readInt, then inspect the related format-parsing methods and their callers. Decide and apply a consistent exception contract for invalid formats, and verify that affected callers can catch the documented exception.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.