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

NullReferenceException related to sorting/paging #229

Closed
1 task done
ivanmonteiro opened this issue May 30, 2020 · 2 comments · Fixed by #230
Closed
1 task done

NullReferenceException related to sorting/paging #229

ivanmonteiro opened this issue May 30, 2020 · 2 comments · Fixed by #230
Labels
bug 🐞 Something isn't working

Comments

@ivanmonteiro
Copy link
Contributor

Overview of the issue

I get the following NullReferenceException when viewing any listing page:

Exception has occurred: CLR/System.NullReferenceException
Ocorreu uma exceção do tipo "System.NullReferenceException" em JHipsterNet.dll, mas ela não foi manipulada no código do usuário: 'Object reference not set to an instance of an object.'
em JHipsterNet.Pagination.Binders.PageableBinder.ResolveSortArgument(QueryString queryString) em src\JHipsterNet\Pagination\Binders\PageableBinder.cs:linha 57
em JHipsterNet.Pagination.Binders.PageableBinder.ResolvePageableArgumentFromQueryString(QueryString queryString) em src\JHipsterNet\Pagination\Binders\PageableBinder.cs:linha 34
em JHipsterNet.Pagination.Binders.PageableBinder.BindModelAsync(ModelBindingContext bindingContext) em src\JHipsterNet\Pagination\Binders\PageableBinder.cs:linha 20
em Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.d__2.MoveNext()

Motivation for or Use Case
Reproduce the error

Using the latest master version, create some entities and go to the listing page of any of the created entities and the exception is thrown on the backend

Related issues

#176

Suggest a Fix

On QueryStringExtensions.cs file change GetParameterValues method:
To this:

        public static string[] GetParameterValues(this QueryString query, string name)
        {
            if (query == null || string.IsNullOrEmpty(name)) return new string[0];
            var parameters = QueryHelpers.ParseQuery(query.ToString());
            return parameters.ContainsKey(name) ? parameters[name].ToArray() :  new string[0];
        }

So the code that uses this method can safely run a foreach with the result without a null reference exeption.

JHipster Version(s)
JHipster configuration

Using master version of this repository

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)
@nicolas63
Copy link
Member

Can you create a PR with the fix and ask @maznag to review ?

@nicolas63 nicolas63 added the bug 🐞 Something isn't working label May 30, 2020
@ivanmonteiro
Copy link
Contributor Author

Can you create a PR with the fix and ask @maznag to review ?

I will do that this weekend

ivanmonteiro added a commit to ivanmonteiro/jhipster-dotnetcore that referenced this issue May 31, 2020
The code that calls the GetParameterValues method throws
NullReferenceException because it expects a string[]
not null.

Fix jhipster#229
maznag added a commit that referenced this issue Jun 1, 2020
Fix #229 - NullReferenceException related to sorting/paging
nicolas63 pushed a commit to nicolas63/jhipster-dotnetcore that referenced this issue Jun 29, 2020
The code that calls the GetParameterValues method throws
NullReferenceException because it expects a string[]
not null.

Fix jhipster#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants