Looking at your code, I assume you are trying to initialize a session for user, before that, you want to check if any existing sessions are there for the user already.
With the given information, Iam not really sure, where it goes wrong, but with the debugging information, it looks like the user does not have any role and may be when initializing the session, mendix expects the role to forward the user to right page.
From what I know, if there is a session already for the user, Mendix will invalidate that session and creates a new one.
- For which simply, you can do Core.initializeSession(user, null);
If you want to look for existing sessions and check get the session id for that user, then you can use Core.getActiveSession(username); and later pass the session id to Core.initializeSession(user, <sessionid>);
If this does not answer the question, post the entire stack trace