Skip to content

com.google.common.collect.GwtPlatform in incompatible with GWT 2.8.0-beta1 #2353

@fkirill

Description

@fkirill

Guava-GWT 18.0 and 19.0 are both incompatible with GWT 2.8.0-beta1. 2.7.0 is working properly.
Both versions reference missing method int GWT core library that is no longer present in 2.8.0.

Interesting aspect is that this problem only appears in SuperDev mode, there is no error message during 'normal' GWT compile.

SuperDev mode produces the following error message:
Compiling module XXXXX
[ERROR] Errors in 'com/google/common/collect/super/com/google/common/collect/GwtPlatform.java'
[ERROR] Line 38: The method createFrom(T[], int) is undefined for the type Array
Tracing compile failure path for type 'com.google.common.collect.GwtPlatform'
[ERROR] Errors in 'com/google/common/collect/super/com/google/common/collect/GwtPlatform.java'
[ERROR] Line 38: The method createFrom(T[], int) is undefined for the type Array

The root cause is in class GwtPlatform (comments removed)

package com.google.common.collect;

import com.google.common.annotations.GwtCompatible;
import com.google.gwt.core.client.GwtScriptOnly;
import com.google.gwt.lang.Array;

@GwtCompatible
@GwtScriptOnly
public final class GwtPlatform {

  private GwtPlatform() {}

  public static <T> T[] newArray(T[] reference, int length) {
    return Array.createFrom(reference, length);
  }
}

As you can see, it references Array.createFrom that was removed in version 2.8.0.

I would suggest the following solution. It doesn't use any internal API and seems to be working cleaner then previous one (Array,createFrom didn't initialize the elements of new array that were not copied from reference and they stayed undefined instead of null).

  public static <T> T[] newArray(T[] reference, int length) {
        T[] res = (T[]) new Object[length];
        if ((reference != null) && (reference.length > 0)) {
            System.arraycopy(reference, 0, res, 0, Math.min(length, reference.length));
        }
        return res;
  }

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions