Git Product home page Git Product logo

Comments (12)

larixer avatar larixer commented on June 19, 2024

Hi @chrisime

This exception is thrown when url is null on one of your pages. I think it's set to null by ResourceMapper of your theme.

Grain is not very helpful with identifying the resource on which url is null, hence I've added resource location printing when this type of error happens to 0.7.0-SNAPSHOT. Please update your application.properties to have the line:
grain.version = 0.7.0-SNAPSHOT

Note, that \n (end of line character) is important at the end of application.properties.

This will help you understand what is the location of resource that has url = null. If everything will be fine I will backport this extended diagnostics into stable Grain version.

Victor

from grain.

chrisime avatar chrisime commented on June 19, 2024

Hi @Vlasenko

Thanks for your reply. Unfortunately, the error still happens in your snapshot version. The url where the NPE is thrown isn't shown.
I double checked my urls and can't think of anything which is wrong.

Any ideas?

Cheers,
Christian

from grain.

larixer avatar larixer commented on June 19, 2024

Hi. The snapshot version was not meant to "fix this error", it will dump extended diagnostic info instead. The error is not in the Grain at all, it's in the theme code. In the stack trace from snapshot version there should be location of the resource with null URL. Please post dumped stack trace here and source code of your ResourceMapper

from grain.

larixer avatar larixer commented on June 19, 2024

Closing due to not a Grain issue and inactivity

from grain.

chrisime avatar chrisime commented on June 19, 2024

Gonna post the problem on the weekend, didn't have time. Please reopen. Thanks!

from grain.

larixer avatar larixer commented on June 19, 2024

Okay, thanks for update. Looking forward to hear from you soon

from grain.

chrisime avatar chrisime commented on June 19, 2024

Hi,

I got the following stacktrace now:

java.lang.RuntimeException: Wrong url 'null' for resource at null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

The relevant parts of ResourceMapper.groovy is (I modified your business theme):

...

    private def customizeModels = { List resources ->
        def posts = resources.findAll { it.layout == 'unternehmer' }
        def isPageable = true

        resources.inject([]) { List updatedResources, Map page ->
            def applyPagination = { items, perPage, url, model = [:] ->
                isPageable = posts.size() > perPage;
                updatedResources += Paginator.paginate(items, 'posts', perPage, url, page + model)
            }
            switch (page.url) {
                case '/':
                case '/pioniere/':
                    applyPagination(posts, 4, page.url)
                    break
                case ~/${site.pioniere_base_dir}.*/:
                    def post = posts.find { it.url == page.url }
                    def index = posts.indexOf(post)
                    def prev = index > 0 ? posts[index - 1] : null
                    def next = posts[index + 1]
                    updatedResources << (page + [prev_post: prev, next_post: next])
                    break
                default:
                    updatedResources << page
            }

            updatedResources << [pageable: isPageable]
        }
    }

    /**
     * Customize site post URLs
     */
    private def customizeUrls = { Map resource ->
        String location = resource.location
        def update = [:]

        switch (location) {
            case ~/\/pioniere\/posts\/.*/:
                update.url = getPostUrl(site.pioniere_base_dir, location)
                break
        }

        resource + update
    }

...

from grain.

larixer avatar larixer commented on June 19, 2024

Hi @chrisime
It's difficult for me to track down where the resource with location = null is born. Can you just print the input of your resource mapper and output of your resource mapper and try to track down where the page with location = null is produced? If it's in the input to resource mapper - it's a bug inside Grain, but if it's in the output - then it's a bug inside resource mapper, since either 'location' or 'source'+'markup' property must be set on each resource produced by resource mapper.

    def map = { resources ->
        println 'Input pages with null location: ' + resources.findAll { !it.location }
        ...
        def refinedResources = resources.findResults(filterPublished).collect {
            customizeUrls <<
                fillDates <<
                resource
        }.sort { -it.date.time }

        def result = customizeModels << refinedResources

        println 'Output pages with null location: ' + result.findAll { !it.location }

        result
    }

from grain.

larixer avatar larixer commented on June 19, 2024

Please note, that the problem in your code is here:

updatedResources << [pageable: isPageable]

You are adding malformed resource with only one property here: [pageable: true/false] and it's location = null of course, because it's not set. You should add pageable property to existing pages instead

from grain.

chrisime avatar chrisime commented on June 19, 2024

Hi @Vlasenko,

so far 'input pages' doesn't give me any null locations. So it seems to be the output.

How can I get around adding malformed resources. I don't see what's wrong since in each case updatedResources gets the right stuff.

Thanks!

from grain.

larixer avatar larixer commented on June 19, 2024

Hi @chrisime,

I've pointed out what's wrong in your code already:
#12 (comment)

You are adding malformed resources in the line of your code pointed out in the comment above. Please see Resource representation of Grain documentation:
http://sysgears.com/grain/docs/latest/#resource-representation

The Groovy map of invalid resource in your case is:
{pageable: false}
which is incorrect, because required keys 'location' and 'url' are absent in this map.

from grain.

chrisime avatar chrisime commented on June 19, 2024

Hello @Vlasenko,

thanks for the link, gonna try this. You can close the issue for now.

Cheers,
Christian

from grain.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.