GrantedAuthority[] arrayAuths = {};  addCustomAuthorities(user.getUsername(), dbAuths);  arrayAuths = (GrantedAuthority[]) dbAuths.toArray(arrayAuths);
GrantedAuthority[] arrayAuths = (GrantedAuthority[]) dbAuths.toArray(new GrantedAuthority[dbAuths.size()]);
    public UserDetails loadUserByUsername(String username)        throws UsernameNotFoundException, DataAccessException {        List users = usersByUsernameMapping.execute(username);        if (users.size() == 0) {            throw new UsernameNotFoundException("User not found");        }        UserDetails user = (UserDetails) users.get(0); // contains no GrantedAuthority[]        List dbAuths = authoritiesByUsernameMapping.execute(user.getUsername());        if (dbAuths.size() == 0) {            throw new UsernameNotFoundException("User has no GrantedAuthority");        }        GrantedAuthority[] arrayAuths = {};        addCustomAuthorities(user.getUsername(), dbAuths);        arrayAuths = (GrantedAuthority[]) dbAuths.toArray(arrayAuths);        String returnUsername = user.getUsername();        if (!usernameBasedPrimaryKey) {            returnUsername = username;        }        return new User(returnUsername, user.getPassword(), user.isEnabled(),            true, true, true, arrayAuths);    }