Search code examples
javamavengwtmigrationgxt

Error of number conversion in GWT 2.6.1 when compiling


During migration of old project I changed version of GWT from 2.0.4 to 2.6.1 and GXT from 2.2.0 to 2.3.1a. When my module is being compiled to javascript I get following error:

'jar:file:/C:/Users/User/.m2/repository/com/google/gwt/gwt-user/2.6.1

/gwt-user-2.6.1.jar!/com/google/gwt/i18n/client/NumberFormat.java'
[INFO]       [ERROR] Line 941: Incompatible conditional operand types Number and BigDecimal
[INFO]       [ERROR] Line 942: Cannot cast from Number to BigDecimal
[INFO]       [ERROR] Line 947: The method valueOf(int) is undefined for the type BigDecimal
[INFO]       [ERROR] Line 952: Incompatible conditional operand types Number and BigInteger
[INFO]       [ERROR] Line 953: Cannot cast from Number to BigInteger
[INFO]       [ERROR] Line 958: The method valueOf(int) is undefined for the type BigInteger

I use gwt-maven-plugin from org.codehaus.mojo. Thought this might be due to incompatible version of java, but I tried both 1.5 and 1.7.

Mentioned fragment of NumberFormat.java

   public String format(Number number) {
    if (number instanceof BigDecimal) {
      BigDecimal bigDec = (BigDecimal) number;
      boolean isNegative = bigDec.signum() < 0;
      if (isNegative) {
        bigDec = bigDec.negate();
      }
      bigDec = bigDec.multiply(BigDecimal.valueOf(multiplier));
      StringBuilder buf = new StringBuilder();
      buf.append(bigDec.unscaledValue().toString());
      format(isNegative, buf, -bigDec.scale());
      return buf.toString();
    } else if (number instanceof BigInteger) {
      BigInteger bigInt = (BigInteger) number;
      boolean isNegative = bigInt.signum() < 0;
      if (isNegative) {
        bigInt = bigInt.negate();
      }
      bigInt = bigInt.multiply(BigInteger.valueOf(multiplier));
      StringBuilder buf = new StringBuilder();
      buf.append(bigInt.toString());
      format(isNegative, buf, 0);
      return buf.toString();
    } else if (number instanceof Long) {
      return format(number.longValue(), 0);
    } else {
      return format(number.doubleValue());
    }
  }

Solution

  • Problem was with deprecated gwt-math dependency in maven. It looks like gwt-math is no longer supported and its content was moved to gwt-user.