Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Intermittent NullPointerException in Firebase Vertex AI Imagen Generation #17199

Open
execute008 opened this issue Mar 15, 2025 · 1 comment · May be fixed by #17211
Open

Bug: Intermittent NullPointerException in Firebase Vertex AI Imagen Generation #17199

execute008 opened this issue Mar 15, 2025 · 1 comment · May be fixed by #17211
Labels
Needs Attention This issue needs maintainer attention. plugin: vertexai label issues for vertexai plugin type: bug Something isn't working

Comments

@execute008
Copy link

Description

When calling generateImages() on the Firebase Vertex AI Imagen model, we're seeing intermittent null pointer exceptions. The error occurs approximately 50% of the time when the function is called.

Error Details

flutter: Image generation error: NoSuchMethodError: The getter 'isEmpty' was called on null.
Receiver: null
Tried calling: isEmpty
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1      new ImagenGenerationResponse.fromJson (package:firebase_vertexai/src/imagen_content.dart:105:21)
#2      parseImagenGenerationResponse (package:firebase_vertexai/src/imagen_content.dart:154:10)
#3      ImagenModel.generateImages.<anonymous closure> (package:firebase_vertexai/src/imagen_model.dart:95:13)

Steps to Reproduce

  1. Initialize the Firebase Vertex AI Imagen model with the following configuration:
final model = FirebaseVertexAI.instance.imagenModel(
  model: 'imagen-3.0-fast-generate-001',
  generationConfig: ImagenGenerationConfig(
    numberOfImages: 1,
    aspectRatio: ImagenAspectRatio.landscape16x9,
    imageFormat: ImagenFormat.jpeg(compressionQuality: 90),
    addWatermark: false,
  ),
);
  1. Call await model.generateImages(prompt) with a valid text prompt

Expected Behavior

The generateImages() method should consistently return valid image data without throwing exceptions.

Actual Behavior

In approximately 50% of the calls, the method throws a NoSuchMethodError because it's trying to call isEmpty on a null value during response parsing in ImagenGenerationResponse.fromJson.

Environment

  • Flutter (3.29.2)
  • firebase_vertexai package (1.4.0)

Possible Causes

Looking at the stack trace, the issue is in ImagenGenerationResponse.fromJson at line 105 in imagen_content.dart. The code is trying to access a property and call isEmpty on it, but is receiving null instead of the expected object or array.

Suggested Fix

The library should add null safety checks in the fromJson method to handle cases where the expected field is missing or null in the API response.

@SelaseKay SelaseKay added type: bug Something isn't working Needs Attention This issue needs maintainer attention. plugin: vertexai label issues for vertexai plugin labels Mar 18, 2025
@SelaseKay SelaseKay linked a pull request Mar 19, 2025 that will close this issue
10 tasks
@SelaseKay
Copy link
Contributor

Hi @execute008, thanks for the detailed report. I have created a PR which should resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention This issue needs maintainer attention. plugin: vertexai label issues for vertexai plugin type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants