ronantakizawa/codereview-bench huggingface dataset:
Repository: PatilShreyas/Foodium
File: app/src/main/java/dev/shreyaspatil/foodium/ui/details/PostDetailsActivity.kt (Kotlin)

Code before:
    override fun getViewBinding(): ActivityPostDetailsBinding =
        ActivityPostDetailsBinding.inflate(layoutInflater)

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> {
                supportFinishAfterTransition()
                return true
            }

            R.id.action_share -> {
                val shareMsg = getString(
                    R.string.share_message,
                    post.title,
                    post.author
                )

                val intent = ShareCompat.IntentBuilder.from(this)
                    .setType("text/plain")
                    .setText(shareMsg)
                    .intent

                if (intent.resolveActivity(packageManager) != null) {
                    startActivity(intent)
                }
                return true
            }
        }

        return super.onOptionsItemSelected(item)
    }

    companion object {
        const val POST_ID = "postId"
    }
}


Review comment (suggestion):
Here we can use `ShareCompat` which was used earlier to generate intent. Please refer previous revision.

Code after:
    override fun getViewBinding(): ActivityPostDetailsBinding =
            ActivityPostDetailsBinding.inflate(layoutInflater)

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> {
                supportFinishAfterTransition()
                return true
            }

            R.id.action_share -> {
                showShareTray()
                return true
            }
        }

        return super.onOptionsItemSelected(item)
    }

    private fun showShareTray() {
        val shareMsg = getString(
                R.string.share_message,
                post.title,
                post.author
        )
        val intent = Intent(Intent.ACTION_SEND)
        intent.apply {
            type = "text/plain"
            putExtra(Intent.EXTRA_TEXT, shareMsg)
            putExtra(Intent.EXTRA_TITLE, post.title)
        }

        startActivity(Intent.createChooser(intent, null))
    }

    companion object {
        const val POST_ID = "postId"
    }
}
Repository: PatilShreyas/Foodium
File: app/src/main/java/dev/shreyaspatil/foodium/ui/details/PostDetailsActivity.kt (Kotlin)

Code before:
                    post.author
                )

                val intent = ShareCompat.IntentBuilder.from(this)
                    .setType("text/plain")
                    .setText(shareMsg)
                    .intent

                if (intent.resolveActivity(packageManager) != null) {
                    startActivity(intent)
                }
                return true
            }
        }

        return super.onOptionsItemSelected(item)
    }

    companion object {
        private const val POST_ID = "postId"

        fun start(context: Context, postId: Int?, options: ActivityOptionsCompat) {
            val intent = Intent(context, PostDetailsActivity::class.java)
            intent.putExtra(POST_ID, postId)
            context.startActivity(intent, options.toBundle())
        }
    }
}


Review comment (suggestion):
This function shouldn't start activity internally using `Context` of the other `Activity`. I referred that blog link which you shared. Means we should be confident who's starting the activity. So it would be great if we start the activity from MainActivity itself. 

I would suggest to make this method like... 👇🏻 

```kotlin

fun getStartIntent(context: Context, postId: Int) = Intent(context, PostDetailsActivity::class.java).apply {
    putExtra(POST_ID, postId)
}
```

From MainActivity, let's do like... 👇🏻 

```kotlin
val intent = PostDetailsActivity.getStartIntent(this, post.id)
startActivity(intent, options.toBundle())
```

Code after:
                )

                val intent = ShareCompat.IntentBuilder.from(this)
                    .setType("text/plain")
                    .setText(shareMsg)
                    .intent

                if (intent.resolveActivity(packageManager) != null) {
                    startActivity(intent)
                }
                return true
            }
        }

        return super.onOptionsItemSelected(item)
    }

    companion object {
        private const val POST_ID = "postId"

        fun getStartIntent(context: Context, postId: Int?) = Intent(context, PostDetailsActivity::class.java).apply {
            putExtra(POST_ID, postId)
        }
    }
}
Repository: PowerShell/PowerShell
File: test/powershell/Modules/Microsoft.PowerShell.Security/CmsMessage2.Tests.ps1 (PowerShell)

Code before:
﻿# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
using namespace System.Security.Cryptography.X509Certificates
using namespace System.Security.Cryptography
function New-CmsRecipient {
  [CmdletBinding(SupportsShouldProcess = $true)]
  [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
  param([String]$Name, [Switch]$Invalid, [String]$OutPfxFile)
  $hash = [HashAlgorithmName]::SHA256
  $pad = [RSASignaturePadding]::Pkcs1
  $oids = [OidCollection]::new()
  $oids.Add("1.3.6.1.4.1.311.80.1") | Out-Null
  $ext1 = [X509KeyUsageExtension]::new([X509KeyUsageFlags]::DataEncipherment, $false)
  $ext2 = [X509EnhancedKeyUsageExtension]::new($oids, $false)
  $req = ([CertificateRequest]::new("CN=$Name", ([RSA]::Create(2048)), $hash, $pad))
  if (!$Invalid) { ($ext1, $ext2).ForEach( { $req.CertificateExtensions.Add($_) }) }
  $certTmp = $req.CreateSelfSigned([datetime]::Now.AddDays(-1), [datetime]::Now.AddDays(365))
  $certBytes = $certTmp.Export([X509ContentType]::Pfx, "tmp")
  [X509KeyStorageFlags[]]$flags = "PersistKeySet", "Exportable"
  $cert = [X509Certificate2]::new($certBytes, "tmp", $flags)
  if ($OutPfxFile) {
    [System.IO.File]::WriteAllBytes($OutPfxFile, $cert.Export([X509ContentType]::Pfx))
  }
  return $cert
}

Describe "CmsMessage cmdlets using X509 cert" -Tags "CI" {

  BeforeAll {

Review comment (security):
```suggestion

using namespace System.Security.Cryptography.X509Certificates
```

Code after:
﻿# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

using namespace System.Security.Cryptography.X509Certificates
using namespace System.Security.Cryptography

function New-CmsRecipient {
    [CmdletBinding(SupportsShouldProcess = $true)]
    [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
    param([String]$Name, [Switch]$Invalid, [String]$OutPfxFile)
    $hash = [HashAlgorithmName]::SHA256
    $pad = [RSASignaturePadding]::Pkcs1
    $oids = [OidCollection]::new()
    $oids.Add("1.3.6.1.4.1.311.80.1") | Out-Null
    $ext1 = [X509KeyUsageExtension]::new([X509KeyUsageFlags]::DataEncipherment, $false)
    $ext2 = [X509EnhancedKeyUsageExtension]::new($oids, $false)
    $req = ([CertificateRequest]::new("CN=$Name", ([RSA]::Create(2048)), $hash, $pad))
    if (!$Invalid) { ($ext1, $ext2).ForEach( { $req.CertificateExtensions.Add($_) }) }
    $certTmp = $req.CreateSelfSigned([datetime]::Now.AddDays(-1), [datetime]::Now.AddDays(365))
    $certBytes = $certTmp.Export([X509ContentType]::Pfx, "tmp")
    [X509KeyStorageFlags[]]$flags = "PersistKeySet", "Exportable"
    $cert = [X509Certificate2]::new($certBytes, "tmp", $flags)
    if ($OutPfxFile) {
        $outfile = New-Item $OutPfxFile -Force
        [System.IO.File]::WriteAllBytes($outfile.FullName, $cert.Export([X509ContentType]::Pfx))
    }
    return $cert
}
Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceSecurity.cs (C#)

Code before:
                        return null;
                    }
                }
                while (userName.Length == 0);
            }

            passwordPrompt = StringUtil.Format(ConsoleHostUserInterfaceSecurityResources.PromptForCredential_Password, userName
            );

            //
            // now, prompt for the password
            //
            WriteToConsole(passwordPrompt, true);
            password = ReadLineAsSecureString();
            if (password == null)
            {
                return null;
            }

            WriteLineToConsole();

            cred = new PSCredential(userName, password);

            return cred;
        }
    }
}



Review comment (suggestion):
Above we try to read user name in a cycle until we get valid name or Crtl-C (null).
I'd expect the same behavior for password too.

Code after:
            string confirmPasswordPrompt = null;
            string passwordMismatch = null;

            if (!string.IsNullOrEmpty(caption))
            {
                // Should be a skin lookup
                WriteLineToConsole();
                WriteLineToConsole(PromptColor, RawUI.BackgroundColor, WrapToCurrentWindowWidth(caption));
            }

            if (!string.IsNullOrEmpty(message))
            {
                WriteLineToConsole(WrapToCurrentWindowWidth(message));
            }

            if (string.IsNullOrEmpty(userName))
            {
                userPrompt = ConsoleHostUserInterfaceSecurityResources.PromptForCredential_User;

                // need to prompt for user name first
                do
                {
                    WriteToConsole(userPrompt, true);
                    userName = ReadLine();
                    if (userName == null)
                    {
                        return null;
                    }
                }
                while (userName.Length == 0);
            }

            passwordPrompt = StringUtil.Format(ConsoleHostUserInterfaceSecurityResources.PromptForCredential_Password, userName);

            // now, prompt for the password
            do
            {
                WriteToConsole(passwordPrompt, true);
                password = ReadLineAsSecureString();
                if (password == null)
                {
                    return null;
                }
            }
            while (password.Length == 0);

            if (confirmPassword)
            {
                confirmPasswordPrompt = StringUtil.Format(ConsoleHostUserInterfaceSecurityResources.PromptForCredential_ReenterPassword, userName);
                passwordMismatch = StringUtil.Format(ConsoleHostUserInterfaceSecurityResources.PromptForCredential_PasswordMismatch);
Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Security/security/CredentialCommands.cs (C#)

Code before:
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(_title, _message, _userName, string.Empty);
            }
            catch (ArgumentException exception)
            {
                ErrorRecord errorRecord = new ErrorRecord(exception, "CouldNotPromptForCredential", ErrorCategory.InvalidOperation, null);
                WriteError(errorRecord);
            }

            if (Credential != null)
            {
                WriteObject(Credential);
            }
        }
    }
}


Review comment (security):
```suggestion
                Credential = this.Host.UI.PromptForCredential(
                    _title,
                    _message,
                    _userName,
                    ReenterPassword,
                    string.Empty,
                    PSCredentialTypes.Default,
                    PSCredentialUIOptions.Default);
```

Code after:
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(
                    _title,
                    _message,
                    _userName,
                    ConfirmPassword,
                    string.Empty,
                    PSCredentialTypes.Default,
                    PSCredentialUIOptions.Default);
            }
            catch (ArgumentException exception)
            {
                ErrorRecord errorRecord = new ErrorRecord(exception, "CouldNotPromptForCredential", ErrorCategory.InvalidOperation, null);
                WriteError(errorRecord);
            }

            if (Credential != null)
            {
                WriteObject(Credential);
            }
        }
    }
}
Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Security/security/CredentialCommands.cs (C#)

Code before:
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(_title, _message, _userName, string.Empty);
            }
            catch (ArgumentException exception)
            {
                ErrorRecord errorRecord = new ErrorRecord(exception, "CouldNotPromptForCredential", ErrorCategory.InvalidOperation, null);
                WriteError(errorRecord);
            }

            if (Credential != null)

Review comment (suggestion):
```suggestion
        public SwitchParameter ReenterPassword { get; set; }
```

Code after:
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Gets or sets the confirm password prompt.
        /// </summary>
        [Parameter(ParameterSetName = messageSet)]
        public SwitchParameter ConfirmPassword { get; set; }

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(
                    _title,
                    _message,
Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Security/security/CredentialCommands.cs (C#)

Code before:
        [ValidateNotNullOrEmpty()]
        public string UserName
        {
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(_title, _message, _userName, string.Empty);
            }
            catch (ArgumentException exception)
            {
                ErrorRecord errorRecord = new ErrorRecord(exception, "CouldNotPromptForCredential", ErrorCategory.InvalidOperation, null);
                WriteError(errorRecord);

Review comment (suggestion):
```suggestion
        /// Gets or sets the re-enter password on the window prompt.
```

Code after:
        [ValidateNotNullOrEmpty()]
        public string UserName
        {
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Gets or sets the confirm password prompt.
        /// </summary>
        [Parameter(ParameterSetName = messageSet)]
        public SwitchParameter ConfirmPassword { get; set; }

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Security/security/CredentialCommands.cs (C#)

Code before:
        {
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(_title, _message, _userName, string.Empty);
            }
            catch (ArgumentException exception)
            {
                ErrorRecord errorRecord = new ErrorRecord(exception, "CouldNotPromptForCredential", ErrorCategory.InvalidOperation, null);
                WriteError(errorRecord);
            }


Review comment (suggestion):
```suggestion
        [Parameter(ParameterSetName = messageSet)]
```

Code after:
        {
            get { return _userName; }

            set { _userName = value; }
        }

        private string _userName = null;

        /// <summary>
        /// Gets and sets the title on the window prompt.
        /// </summary>
        [Parameter(Mandatory = false, ParameterSetName = messageSet)]
        [ValidateNotNullOrEmpty]
        public string Title
        {
            get { return _title; }

            set { _title = value; }
        }

        private string _title = UtilsStrings.PromptForCredential_DefaultCaption;

        /// <summary>
        /// Gets or sets the confirm password prompt.
        /// </summary>
        [Parameter(ParameterSetName = messageSet)]
        public SwitchParameter ConfirmPassword { get; set; }

        /// <summary>
        /// Initializes a new instance of the GetCredentialCommand
        /// class.
        /// </summary>
        public GetCredentialCommand() : base()
        {
        }

        /// <summary>
        /// The command outputs the stored PSCredential.
        /// </summary>
        protected override void BeginProcessing()
        {
            if (Credential != null)
            {
                WriteObject(Credential);
                return;
            }

            try
            {
                Credential = this.Host.UI.PromptForCredential(
                    _title,