String Handling in ELArithmetic is not correct

Open Beginner friendly
#24 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start in ELArithmetic at the protected coerce(Object) method shown in the issue, and trace the order of its number, String, null, and empty-string checks. Verify whether the empty-string branch is reachable and what behavior the existing tests expect; done means the conversion behavior is correct and covered by an appropriate test.

Written by the indexing model from the issue text.

Description

protected final Number coerce(final Object obj) {

        if (isNumber(obj)) {
            return coerce((Number) obj);
        }
        if (obj instanceof String) {
            return coerce((String) obj);
        }
        if (obj == null || "".equals(obj)) {  
            return coerce(ZERO);
        }

        Class<?> objType = obj.getClass();
        if (Character.class.equals(objType) || Character.TYPE == objType) {
            return coerce(Short.valueOf((short) ((Character) obj).charValue()));
        }

        throw new IllegalArgumentException(MessageFactory.get("el.convert", obj, objType));
    }

The "".equals(obj) part can never be reache or?

Dominant language
Java
Stars
15
Forks
10
PR merge metrics
No merged PRs in 30d

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.

More from eclipse-ee4j/expressly

All issues in eclipse-ee4j/expressly

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.