Skip to content

Blob.lastModifiedDate declared as String but browser returns JS Date object — breaks with GWT 2.13 #444

@ihorshu

Description

@ihorshu

Blob.java declares lastModifiedDate as public String in a @jstype(isNative=true) class:

@JsType(isNative = true, name = "Blob", namespace = JsPackage.GLOBAL)
public class Blob {
    @JsProperty
    public String lastModifiedDate;
    // ...
}

However, the browser's File.lastModifiedDate returns a JS Date object, not a string. This type mismatch has always been present but was harmless until GWT 2.13.

What breaks in GWT 2.13:

GWT 2.13 added CharSequence.isEmpty() as a default method (gwtproject/gwt#10091). The devirtualizer now emits a runtime instanceOfString check:

// Generated JS for isEmpty() call in convertUploadFile()
instanceOfString(this$static)
    ? String.$isEmpty(this$static)      // string path
    : this$static.isEmpty__Z();          // non-string path ← crashes here

Since file.lastModifiedDate is a JS Date at runtime, typeof date === 'string' is false, and Date.isEmpty__Z() doesn't exist → TypeError.

The crash occurs in MaterialFileUploader.convertUploadFile():

if (file.lastModifiedDate != null && !file.lastModifiedDate.isEmpty()) {
    lastModifiedDate = new Date(file.lastModifiedDate);
}

Additional note: File.lastModifiedDate is deprecated in the browser API. The modern replacement is File.lastModified which returns a numeric timestamp (milliseconds since epoch).

Suggested fix:

Replace the String lastModifiedDate field in Blob.java with the modern numeric API, and update convertUploadFile():

// In Blob.java — replace:
//   public String lastModifiedDate;
// with:
@JsProperty
public double lastModified;
// In MaterialFileUploader.convertUploadFile() — replace the date parsing with:
Date lastModifiedDate = new Date((long) file.lastModified);

This uses the modern, non-deprecated browser API and avoids calling any Java String methods on native JS values.

Environment: GWT 2.13.0, gwt-material-addins 2.8.5

Ref: gwtproject/gwt#10298

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions