marinasundstrom / CheckedExceptions

Enforce better exception handling in C#/.NET by ensuring exceptions are explicitly handled.
MIT License
7 stars 1 forks source link

``ArgumentNullException`` annotation not respected in nullable #48

Closed marinasundstrom closed 6 days ago

marinasundstrom commented 6 days ago

ArgumentNullException should not be reported.

It is in the filter logic - only being on exception types from XML doc.

    /// <summary>
    /// Analyzes exceptions thrown by a method, constructor, or other member.
    /// </summary>
    private void AnalyzeMemberExceptions(SyntaxNodeAnalysisContext context, SyntaxNode node, IMethodSymbol methodSymbol,
        AnalyzerConfig options)
    {
        if (methodSymbol == null)
            return;

        List<INamedTypeSymbol?> exceptionTypes = GetExceptionTypes(methodSymbol);

        // Get exceptions from XML documentation
        var xmlExceptionTypes = GetExceptionTypesFromDocumentationCommentXml(context.Compilation, methodSymbol);

        xmlExceptionTypes = ProcessNullable(context, node, methodSymbol, xmlExceptionTypes);

        if (xmlExceptionTypes.Any())
        {
            exceptionTypes.AddRange(xmlExceptionTypes.Select(x => x.ExceptionType));
        }

        foreach (var exceptionType in exceptionTypes.Distinct(SymbolEqualityComparer.Default).OfType<INamedTypeSymbol>())
        {
            AnalyzeExceptionThrowingNode(context, node, exceptionType, options);
        }
    }
marinasundstrom commented 6 days ago

We will have to revisit this filter logic in the future.