Migrate to Java Admin SDK v7 Stay organized with collections Save and categorize content based on your preferences.
Version 7.0.0 of the Firebase Admin SDK for Java introduces some importantchanges in the API. Primarily, the API changes in this release are additions andimprovements in error handling forAuthentication amdFCM.
General error handling changes
FirebaseException base class now exposes several new attributes:
ErrorCode getErrorCode(): Returns the platform error code associated with the exception. Every instance ofFirebaseExceptionis guaranteed to have a non-null platform error code. Possible platform error codes are defined as a new enum typeErrorCode.IncomingHttpResponse getHttpResponse(): Returns the HTTP response associated with the exception. May be null if the exception was caused by a reason other than a backend HTTP response.
Like before, most other exception types defined in the SDK (for example,FirebaseAuthException,FirebaseMessagingException) are derived from theFirebaseException base class.
Auth error handling changes
All APIs in theFirebaseAuth class may throw instances ofFirebaseAuthException. Async APIs (for instance, methods that return anApiFuture) may fail with anExecutionException that wraps aFirebaseAuthException. The Auth-specific error codes are publicly defined inthe new enum typeAuthErrorCode.
Before (<= v6.15.0)
try{FirebaseAuth.getInstance().verifyIdToken(idToken,true);}catch(FirebaseAuthExceptionex){if(ex.getErrorCode().equals("id-token-revoked")){System.err.println("ID token has been revoked");}else{System.err.println("ID token is invalid");}}Now (>= v7.0.0)
try{FirebaseAuth.getInstance().verifyIdToken(idToken,true);}catch(FirebaseAuthExceptionex){if(ex.getAuthErrorCode()==AuthErrorCode.REVOKED_ID_TOKEN){System.err.println("ID token has been revoked");}else{System.err.println("ID token is invalid");}}TheAuthErrorCode is in addition to theErrorCode inherited from the baseFirebaseException type. You can implement error handling logic that inspectsboth error codes if necessary.
FCM error handling changes
All APIs inFirebaseMessaging class may throw instances ofFirebaseMessagingException. Async APIs (for instance, methods that return anApiFuture) may fail with anExecutionException that wraps aFirebaseMessagingException. TheAuthentication-specific error codes are publiclydefined in the new enum typeMessagingErrorCode.
Before (<= v6.15.0)
try{FirebaseMessaging.getInstance().send(message);}catch(FirebaseMessagingExceptionex){if(ex.getErrorCode().equals("registration-token-not-registered")){System.err.println("Device token has been unregistered");}else{System.err.println("Failed to send the notification");}}Now (>= v7.0.0)
try{FirebaseMessaging.getInstance().send(message);}catch(FirebaseMessagingExceptionex){if(ex.getMessagingErrorCode()==MessagingErrorCode.UNREGISTERED){System.err.println("Device token has been unregistered");}else{System.err.println("Failed to send the notification");}}TheMessagingErrorCode is in addition to theErrorCode inherited from thebaseFirebaseException type. You can implement error handling logic thatinspects both error codes if necessary.
Authentication custom claims
The deprecatedFirebaseAuth.setCustomClaims() method has been removed. Use theFirebaseAuth.setCustomUserClaims() instead.
Before (<= v6.15.0)
FirebaseAuth.getInstance().setCustomClaims(uid,claims);Now (>= v7.0.0)
FirebaseAuth.getInstance().setCustomUserClaims(uid,claims);FCM notification constructors
The deprecated constructors of theNotification class have been removed. UsetheNotification.Builder class to create new instances.
Before (<= v6.15.0)
Notificationnotification=newNotification(title,body,url);Now (>= v7.0.0)
Notificationnotification=Notification.builder().setTitle(title).setBody(body).setImage(url).build();Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.