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

[Bug] NullPointerException during content generation #9782

Closed
thejonan opened this issue Mar 12, 2024 · 4 comments · Fixed by #9786
Closed

[Bug] NullPointerException during content generation #9782

thejonan opened this issue Mar 12, 2024 · 4 comments · Fixed by #9786
Labels
bug A bug to fix

Comments

@thejonan
Copy link

Describe the bug
A NullPointerException during tool execution, after updating to version 2.75.3 (previous version used is 2.66.2 and the error did not show up).

Here's the stack trace:

NullReferenceException: Object reference not set to an instance of an object.
  at ConfigFilterRuleItem get_Rule() in ConfigFilterRuleItemUnion.cs:57
  at bool CanVisitCore(IEnumerable<ConfigFilterRuleItemUnion> ruleItems, SymbolFilterData symbol) in ConfigFilterRule.cs:
     30
  at bool CanVisitApi(SymbolFilterData symbol) in ConfigFilterRule.cs:20
  at bool <IncludeApi>g__IncludeApiDefault|1(ISymbol symbol) in SymbolFilter.cs:46
  at bool <IncludeApi>b__0(ISymbol _) in SymbolFilter.cs:40
  at TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
  at bool IncludeApi(ISymbol symbol) in SymbolFilter.cs:31
  at IEnumerable<INamespaceSymbol> GetAllNamespaces(IAssemblySymbol assembly, SymbolFilter filter) in SymbolHelper.cs:106
  at IEnumerable<TResult> SelectManyIterator<TSource,TCollection,TResult>(IEnumerable<TSource> source, Func<TSource,
     IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
  at bool MoveNext()
  at IEnumerable<TResult> SelectManyIterator<TSource,TCollection,TResult>(IEnumerable<TSource> source, Func<TSource,
     IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
  at bool MoveNext()
  at void AddRange(IEnumerable<T> items)
  at bool ReserveOrAdd(IEnumerable<T> items)
  at TResult[[]] ToArray()
  at void CreateManagedReference((ValueTuple<IAssemblySymbol, Compilation> symbol) assemblies, ExtractMetadataConfig
     config, DotnetApiOptions options) in DotnetApiCatalog.ManagedReference.cs:19
  at async Task <Exec>g__Build|5_0(ExtractMetadataConfig config, DotnetApiOptions options) in DotnetApiCatalog.cs:123
  at async Task Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory)
     in DotnetApiCatalog.cs:75
  at void <Execute>b__0() in DefaultCommand.cs:45
  at int Run(LogOptions options, Action run) in CommandHelper.cs:48
  at int Execute(CommandContext context, Options options) in DefaultCommand.cs:31
  at Task<int> Execute(CommandContext context, CommandSettings settings) in CommandOfT.cs:40
  at Task<int> Execute(CommandTree leaf, CommandTree tree, CommandContext context, ITypeResolver resolver, IConfiguration
     configuration) in CommandExecutor.cs:144
  at async Task<int> Execute(IConfiguration configuration, IEnumerable<string> args) in CommandExecutor.cs:83
  at async Task<int> RunAsync(IEnumerable<string> args) in CommandApp.cs:84

Here is a (modified) configuration file:

{
  "metadata": [{
    "src": [{
      "files": ["CoreProject.csproj"],
      "src": "../"
    }, {
      "files": ["DependentProject1.csproj", "DependentProject2.csproj"],
      "src": "../"
    }],
    "dest": "api",
    "filter": "docfx-filter-config.yml",
    "disableGitFeatures": true,
    "disableDefaultFilter": false
  }],
  "build": {
    "content": [{
      "files": ["**.yml", "**.md"],
      "exclude": "docfx-filter-config.yml"
    }],
    "resource": [{
      "files": ["images/**"]
    }],
    "overwrite": [{
      "files": ["**.md"],
      "exclude": [
        "obj/**",
        "bin/**",
        "_site/**"
      ]
    }],
    "dest": "../public",
    "_globalMetadata": {
      "_appTitle": "Custom API",
      "_enableSearch": true
    },
    "globalMetadataFiles": [],
    "fileMetadataFiles": [],
    "template": ["default"],
    "postProcessors": [],
    "noLangKeyword": false,
    "keepFileLink": false,
    "cleanupCacheHistory": true,
    "disableGitFeatures": true,
    "force": true
  }
}

And here is the filter file referred:

apiRules:
- include:
  uidRegex: ^MyCompany\.MyNamespace\.Core.+
- exclude:
  uidRegex: _[^.]+$

The command used to invoke the generation is:

./bin/docfx Docs/docfx.json --serve

Context (please complete the following information):

  • macOS (Sonoma 14.3.1)
  • Linux (mcr.microsoft.com/dotnet/sdk:7.0 docker image).
  • Docfx version: 2.75.3
@thejonan thejonan added the bug A bug to fix label Mar 12, 2024
@filzrev
Copy link
Contributor

filzrev commented Mar 12, 2024

uidRegex must be defined with indentation as follows

apiRules:
- include:
    uidRegex: ^MyCompany\.MyNamespace\.Core.+
- exclude:
    uidRegex: _[^.]+$

Error is occurred at following lines

// If kind is not specified for exclude. Set `ExtendedSymbolKind.Type` as default kind.
Exclude.Kind ??= ExtendedSymbolKind.Type | ExtendedSymbolKind.Member;

that lines are added by #9666.
I'll create PR to fix problems later.

For prior than docfx 2.75.2.
uidRegex is simply ignored on YAML deserialization. and include/exclude rules are ignored. if defined without indents.

@thejonan
Copy link
Author

Thanks for the quick response!

So, now uidRegex for both include and exclude will be taken into account?

@filzrev
Copy link
Contributor

filzrev commented Mar 12, 2024

now uidRegex for both include and exclude will be taken into account?

As far as I've tested with 2.75.3 with modified filterConfig.
Specified exclude rule works as expected (types that uid contains _ is not included at API metadata).

For specified include rule.
It don't affect filtering behaviors because public types are already included by default.

@thejonan
Copy link
Author

Ok. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug to fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants