how to resolve java.lang.IllegalStateException: Task is not yet complete Error when uploading image to Firebase storage?

I figured it out ,didn't know that uploading task api has changed a little bit, it uses a continuation to retrieve the download uri just as follow:

final StorageReference imagesRef= storageRef.child("images/my_image.jpg");
urlTask = imagesRef.putFile(file);    
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
            @Override
            public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }

                // Continue with the task to get the download URL
                return imagesRef.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    if (downloadUri == null)
                        return ;
                    else
                    doWhateverYouWant(downloadUri);

       }
        });