ronantakizawa/codereview-bench huggingface dataset:
Repository: thunderbird/thunderbird-android
File: core/ui/compose/preference/src/main/kotlin/net/thunderbird/core/ui/compose/preference/ui/components/list/PreferenceItem.kt (Kotlin)

Code before:

        is PreferenceSetting.Color -> {
            PreferenceItemColorView(
                preference = preference,
                onClick = onClick,
                modifier = modifier,
            )
        }

        is PreferenceSetting.SingleChoice -> {
            PreferenceItemSingleChoiceView(
                preference = preference,
                onPreferenceChange = onPreferenceChange,
                modifier = modifier,
            )
        }

        is PreferenceSetting.Switch -> {
            PreferenceItemSwitchView(
                preference = preference,
                onPreferenceChange = onPreferenceChange,
                modifier = modifier,
            )
        }

        is PreferenceSetting.SingleChoiceCompact -> Unit

        // PreferenceDisplay
        is PreferenceDisplay.Custom -> {
            PreferenceItemCustomView(
                preference = preference,
                modifier = modifier,
            )
        }

        is PreferenceDisplay.SectionHeader -> {
            PreferenceItemSectionHeaderView(
                preference = preference,
                modifier = modifier,
            )
        }

        is PreferenceDisplay.SectionDivider -> {
            PreferenceItemSectionDividerView(
                modifier = modifier,
            )
        }
    }
}


Review comment (suggestion):
This should still render the list item similarly to the `PreferenceItemColorView` just rendering the current selected value.

Code after:

        is PreferenceSetting.Color -> {
            PreferenceItemColorView(
                preference = preference,
                onClick = onClick,
                modifier = modifier,
            )
        }

        is PreferenceSetting.SingleChoice -> {
            PreferenceItemSingleChoiceView(
                preference = preference,
                onPreferenceChange = onPreferenceChange,
                modifier = modifier,
            )
        }

        is PreferenceSetting.Switch -> {
            PreferenceItemSwitchView(
                preference = preference,
                onPreferenceChange = onPreferenceChange,
                modifier = modifier,
            )
        }

        is PreferenceSetting.SingleChoiceCompact -> PreferenceItemSingleChoiceCompactView(
            preference = preference,
            onClick = onClick,
            modifier = modifier,
        )

        // PreferenceDisplay
        is PreferenceDisplay.Custom -> {
            PreferenceItemCustomView(
                preference = preference,
                modifier = modifier,
            )
        }

        is PreferenceDisplay.SectionHeader -> {
            PreferenceItemSectionHeaderView(
                preference = preference,
                modifier = modifier,
            )
        }

        is PreferenceDisplay.SectionDivider -> {
            PreferenceItemSectionDividerView(
                modifier = modifier,
            )
        }
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    private var utf8 = false

    fun encode(folderName: String): String {
        if (utf8) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (utf8) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }


Review comment (suggestion):
This property name is not descriptive enough. Please rename it to a more informative name. Additionally, consider making this property public since a setter method has been added to toggle it on or off.

```suggestion
    var acceptUtf8Encoding = false
```

Code after:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    var acceptUtf8Encoding = false

    fun encode(folderName: String): String {
        if (acceptUtf8Encoding) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (acceptUtf8Encoding) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    private var utf8 = false

    fun encode(folderName: String): String {
        if (utf8) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (utf8) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }

    fun setUtf8Accept(y: Boolean) {
        utf8 = y
    }

Review comment (suggestion):
```suggestion
        if (acceptUtf8Encoding) {
```

Code after:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    var acceptUtf8Encoding = false

    fun encode(folderName: String): String {
        if (acceptUtf8Encoding) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (acceptUtf8Encoding) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    private var utf8 = false

    fun encode(folderName: String): String {
        if (utf8) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (utf8) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }

    fun setUtf8Accept(y: Boolean) {
        utf8 = y
    }
}


Review comment (suggestion):
```suggestion
        if (acceptUtf8Encoding) {
```

Code after:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    var acceptUtf8Encoding = false

    fun encode(folderName: String): String {
        if (acceptUtf8Encoding) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (acceptUtf8Encoding) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt (Kotlin)

Code before:
        if (utf8) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (utf8) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }

    fun setUtf8Accept(y: Boolean) {
        utf8 = y
    }
}


Review comment (suggestion):
Unless you need a custom logic that isn't only a setter method, please use a Kotlin property instead.
```suggestion
```

Code after:
package com.fsck.k9.mail.store.imap

import com.beetstra.jutf7.CharsetProvider
import java.nio.ByteBuffer
import java.nio.charset.CodingErrorAction
import java.nio.charset.StandardCharsets

internal class FolderNameCodec {
    private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
    private val asciiCharset = StandardCharsets.US_ASCII
    var acceptUtf8Encoding = false

    fun encode(folderName: String): String {
        if (acceptUtf8Encoding) {
            return folderName
        }

        val byteBuffer = modifiedUtf7Charset.encode(folderName)
        val bytes = ByteArray(byteBuffer.limit())
        byteBuffer.get(bytes)

        return String(bytes, asciiCharset)
    }

    fun decode(encodedFolderName: String): String {
        if (acceptUtf8Encoding) {
            return encodedFolderName
        }

        val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
        val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
        val charBuffer = decoder.decode(byteBuffer)

        return charBuffer.toString()
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseHelper.java (Java)

Code before:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.fsck.k9.mail.filter.PeekableInputStream;


public class ImapResponseHelper {
    public static List<ImapResponse> createImapResponseList(String... responses) throws IOException {
        List<ImapResponse> imapResponses = new ArrayList<>();
        for (String response : responses) {
            imapResponses.add(createImapResponse(response));
        }
        return imapResponses;
    }

    public static ImapResponse createImapResponse(String response) throws IOException {
        return createImapResponse(response, false);
    }

    public static ImapResponse createImapResponse(String response, boolean utf8) throws IOException {
        String input = response + "\r\n";
        PeekableInputStream inputStream = new PeekableInputStream(new ByteArrayInputStream(input.getBytes()));
        ImapResponseParser parser = new ImapResponseParser(inputStream);
        parser.setUtf8Accepted(utf8);

        return parser.readResponse();
    }

    public static Set<Long> createNonContiguousIdSet(long start, long end, int interval) {
        Set<Long> ids = new HashSet<>();
        for (long i = start;i <= end;i += interval) {
            ids.add(i);
        }
        return ids;
    }
}


Review comment (suggestion):
You missed adding the new constructor parameter for `ImapResponseParser`, which will cause a compilation error in the tests.
```suggestion
        ImapResponseParser parser = new ImapResponseParser(inputStream, new FolderNameCodec());
```

Code after:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.fsck.k9.mail.filter.PeekableInputStream;


public class ImapResponseHelper {
    public static List<ImapResponse> createImapResponseList(String... responses) throws IOException {
        List<ImapResponse> imapResponses = new ArrayList<>();
        for (String response : responses) {
            imapResponses.add(createImapResponse(response));
        }
        return imapResponses;
    }

    public static ImapResponse createImapResponse(String response) throws IOException {
        return createImapResponse(response, false);
    }

    public static ImapResponse createImapResponse(String response, boolean utf8) throws IOException {
        String input = response + "\r\n";
        PeekableInputStream inputStream = new PeekableInputStream(new ByteArrayInputStream(input.getBytes()));
        ImapResponseParser parser = new ImapResponseParser(inputStream, new FolderNameCodec());
        parser.setUtf8Accepted(utf8);

        return parser.readResponse();
    }

    public static Set<Long> createNonContiguousIdSet(long start, long end, int interval) {
        Set<Long> ids = new HashSet<>();
        for (long i = start;i <= end;i += interval) {
            ids.add(i);
        }
        return ids;
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/AlertResponse.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.store.imap.ImapResponseParser.equalsIgnoreCase

@Suppress("ReturnCount", "MagicNumber")
object AlertResponse {
    private const val ALERT_RESPONSE_CODE = "ALERT"

    @JvmStatic
    fun getAlertText(response: ImapResponse): String? {
        if (response.size < 3 || !response.isList(1)) {
            return null
        }

        val responseTextCode = response.getList(1)
        if (responseTextCode.size != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) {
            return null
        }

        return response.getString(2)
    }
}


Review comment (suggestion):
We should avoid adding suppressions in the code when possible. 

- The `ReturnCount` issue can be resolved by utilizing the `return if` approach.
- The `MagicNumber` warning can be addressed by defining a constant for the number 3, which appears on line 11.

Please let me know if you need help to address this

Code after:
package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.store.imap.ImapResponseParser.equalsIgnoreCase

internal object AlertResponse {
    private const val ALERT_RESPONSE_CODE = "ALERT"
    private const val MINIMUM_RESPONSE_SIZE = 3

    @JvmStatic
    fun getAlertText(response: ImapResponse): String? {
        return if (
            response.size >= MINIMUM_RESPONSE_SIZE &&
            response.isList(1)
        ) {
            val responseTextCode = response.getList(1)
            if (responseTextCode.size == 1 && equalsIgnoreCase(responseTextCode[0], ALERT_RESPONSE_CODE)) {
                response.getString(2)
            } else {
                null
            }
        } else {
            null
        }
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/AlertResponse.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.store.imap.ImapResponseParser.equalsIgnoreCase

object AlertResponse {
    private const val ALERT_RESPONSE_CODE = "ALERT"
    private const val MINIMUM_RESPONSE_SIZE = 3

    @JvmStatic
    fun getAlertText(response: ImapResponse): String? {
        return if (
            response.size >= MINIMUM_RESPONSE_SIZE &&
            response.isList(1)
        ) {
            val responseTextCode = response.getList(1)
            if (responseTextCode.size == 1 && equalsIgnoreCase(responseTextCode[0], ALERT_RESPONSE_CODE)) {
                response.getString(2)
            } else {
                null
            }
        } else {
            null
        }
    }
}


Review comment (suggestion):
Sorry about that, but I've just noticed that the `AlertResponse` should be internal. Therefore, there's no need to change the visibility of `ImapResponse`.

Code after:
package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.store.imap.ImapResponseParser.equalsIgnoreCase

internal object AlertResponse {
    private const val ALERT_RESPONSE_CODE = "ALERT"
    private const val MINIMUM_RESPONSE_SIZE = 3

    @JvmStatic
    fun getAlertText(response: ImapResponse): String? {
        return if (
            response.size >= MINIMUM_RESPONSE_SIZE &&
            response.isList(1)
        ) {
            val responseTextCode = response.getList(1)
            if (responseTextCode.size == 1 && equalsIgnoreCase(responseTextCode[0], ALERT_RESPONSE_CODE)) {
                response.getString(2)
            } else {
                null
            }
        } else {
            null
        }
    }
}
Repository: thunderbird/thunderbird-android
File: mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapResponse.kt (Kotlin)

Code before:
package com.fsck.k9.mail.store.imap

import java.io.Serializable

/**
 * Represents a single response from the IMAP server.
 *
 * Tagged responses have a non-null tag.
 * Untagged responses have a null tag.
 * Continuation requests are identified with a `+`.
 */
internal class ImapResponse private constructor(
    var callback: ImapResponseCallback?,
    val isContinuationRequested: Boolean,
    val tag: String?,
) : ImapList(), Serializable {

    companion object {
        private const val serialVersionUID: Long = 6886458551615975669L

        @JvmStatic
        fun newContinuationRequest(callback: ImapResponseCallback?): ImapResponse {
            return ImapResponse(callback, true, null)
        }

        @JvmStatic
        fun newUntaggedResponse(callback: ImapResponseCallback?): ImapResponse {
            return ImapResponse(callback, false, null)
        }

        @JvmStatic
        fun newTaggedResponse(callback: ImapResponseCallback?, tag: String): ImapResponse {
            return ImapResponse(callback, false, tag)
        }
    }

Review comment (suggestion):
Just missing part of the old java docs:

```suggestion
 * Continuation requests are identified with a `+`.
 * The object will contain all of the available tokens at the time the response is received.
```

Code after:
package com.fsck.k9.mail.store.imap

import java.io.Serializable

/**
 * Represents a single response from the IMAP server.
 *
 * Tagged responses have a non-null tag.
 * Untagged responses have a null tag.
 * Continuation requests are identified with a `+`.
 * The object will contain all of the available tokens at the time the response is received.
 */
internal class ImapResponse private constructor(
    var callback: ImapResponseCallback?,
    val isContinuationRequested: Boolean,
    val tag: String?,
) : ImapList(), Serializable {

    companion object {
        private const val serialVersionUID: Long = 6886458551615975669L

        @JvmStatic
        fun newContinuationRequest(callback: ImapResponseCallback?): ImapResponse {
            return ImapResponse(callback, true, null)
        }

        @JvmStatic
        fun newUntaggedResponse(callback: ImapResponseCallback?): ImapResponse {
            return ImapResponse(callback, false, null)
        }

        @JvmStatic
        fun newTaggedResponse(callback: ImapResponseCallback?, tag: String): ImapResponse {
            return ImapResponse(callback, false, tag)
        }