Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update S2681: Fix FP on try-catch block #343

Closed
jccollet opened this issue May 23, 2017 · 1 comment
Closed

Update S2681: Fix FP on try-catch block #343

jccollet opened this issue May 23, 2017 · 1 comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@jccollet
Copy link
Contributor

The following code triggers rule S2681 (Multiline blocks should be enclosed in curly braces) on the 'try {' line. Obviously a FP.
See Issue on peach

using System;

namespace MyLibrary {
    public class MyClass {
        internal static void ReadBytesAsync (
            this Stream stream, int length, Action<byte[]> completed, Action<Exception> error) {
            var buffer = new byte[length];
            stream.BeginRead (
                buffer,
                0,
                length,
                ar => {
                    try {
                        var len = stream.EndRead (ar);
                        var bytes = len < 1 ?
                            new byte[0] :
                            len < length ?
                            stream.readBytes (buffer, len, length - len) :
                            buffer;
                        if (completed != null)
                            completed (bytes);
                    } catch (Exception ex) {
                        if (error != null)
                            error (ex);
                    }
                },
                null);
        }
    }
}
@jccollet jccollet added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels May 23, 2017
@jccollet jccollet added this to the 5.11 milestone May 23, 2017
@valhristov valhristov changed the title S2681: FP on try-catch block Update S2681: Fix FP on try-catch block May 23, 2017
@valhristov valhristov modified the milestones: 5.12, 5.11 May 23, 2017
@valhristov
Copy link
Contributor

Duplicates #264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants