Skip to content

Commit 95e4956

Browse files
YuriiZaripayurii.zaripa
andauthored
[BKNDLSS-28440]:ISE if get userRole for undefined user (#518)
* [BKNDLSS-28440]:ISE if get userRole for undefined user * [BKNDLSS-28440]:Make change more compact Co-authored-by: yurii.zaripa <[email protected]>
1 parent c65fb06 commit 95e4956

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/com/backendless/UserService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.backendless.utils.ResponderHelper;
3636
import weborb.types.Types;
3737

38+
import java.util.Collections;
3839
import java.util.ArrayList;
3940
import java.util.Arrays;
4041
import java.util.HashMap;
@@ -686,7 +687,9 @@ public List<String> getUserRoles( String userId )
686687
if( userId == null || userId.isEmpty() )
687688
throw new IllegalArgumentException( ExceptionMessage.NULL_IDENTITY );
688689

689-
return Arrays.asList( (String[]) Invoker.invokeSync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { userId } ) );
690+
Object[] objects = Invoker.invokeSync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { userId } );
691+
692+
return objects.length == 0 ? Collections.<String>emptyList() : Arrays.asList( (String[]) objects );
690693
}
691694

692695
public void getUserRoles( final AsyncCallback<List<String>> responder )
@@ -709,7 +712,7 @@ public void handleFault( BackendlessFault fault )
709712
responder.handleFault( fault );
710713
}
711714
};
712-
Invoker.invokeAsync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] { }, callback );
715+
Invoker.invokeAsync( USER_MANAGER_SERVER_ALIAS, "getUserRoles", new Object[] {}, callback );
713716
}
714717
catch( Throwable e )
715718
{
@@ -725,13 +728,13 @@ public void getUserRoles( String userId, final AsyncCallback<List<String>> respo
725728
if( userId == null || userId.isEmpty() )
726729
throw new IllegalArgumentException( ExceptionMessage.NULL_IDENTITY );
727730

728-
AsyncCallback<String[]> callback = new AsyncCallback<String[]>()
731+
AsyncCallback<Object[]> callback = new AsyncCallback<Object[]>()
729732
{
730733
@Override
731-
public void handleResponse( String[] response )
734+
public void handleResponse( Object[] response )
732735
{
733736
if( responder != null )
734-
responder.handleResponse( Arrays.asList( response ) );
737+
responder.handleResponse( response.length == 0 ? Collections.<String>emptyList() : Arrays.asList( (String[]) response ) );
735738
}
736739

737740
@Override

0 commit comments

Comments
 (0)