Почему элемент пропадает из ArrayList?

У меня есть netty-сервер, который принимает почту и пароль для регистрации нового аккаунта, но по какой-то причине после создания, аккаунт бесследно исчезает.

Обработчик пакета регистрации:

public void packRegisterRead(ChannelHandlerContext ctx, ByteBuf in) {
        int emailLength = in.readInt();
        int passwordLength = in.readInt();
        ByteBuf emailBuf = in.readBytes(emailLength);
        ByteBuf passwordBuf = in.readBytes(passwordLength);
        String email = StandardCharsets.UTF_8.decode(emailBuf.nioBuffer()).toString(),
                password = StandardCharsets.UTF_8.decode(passwordBuf.nioBuffer()).toString();
        boolean create = true;
        for (int i = 0; i < handler.logic.accounts.size(); i++) {
            System.out.println(handler.logic.accounts.get(i).email + " | " + handler.logic.accounts.get(i).password);
            if (handler.logic.accounts.get(i).email.equals(email)) {
                create = false;
                i = handler.logic.accounts.size();
            }
        }
        if (create) {
            Account account = new Account(ctx, email, password);
            System.out.println(account.email + " | " + account.password);
            handler.logic.accounts.add(account);
            System.out.println(handler.logic.accounts.size() + " accounts");
            account.output.writeBoolean(true);
            UtilsFunctions.write(ctx, account.output, UtilsPackages.PACK_REGISTER);
        }
        else {
            ByteBuf output = ctx.alloc().buffer(1024);
            output.writeBoolean(false);
            UtilsFunctions.write(ctx, output, UtilsPackages.PACK_REGISTER);
        }
        System.out.println(create);
    }

Вывод в консоли после 2-ух попыток регистрации с одинаковыми почтами и паролями и 1-ой попытки регистрации с другими почтой и паролем:

Read 4 package, address: /192.168.1.60:59542 , name: ServerHandler#0
yarr | 123
1 accounts
Written 4 package
true
Read 4 package, address: /192.168.1.60:59569 , name: ServerHandler#0
yarr | 123
1 accounts
Written 4 package
true
Read 4 package, address: /192.168.1.60:59606 , name: ServerHandler#0
oleg | 999
1 accounts
Written 4 package
true
  • Вопрос задан
  • 96 просмотров
Решения вопроса 1
@Yarru Автор вопроса
Я уже нашёл ответ, я просто пересоздавал список.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы