Comments (12)
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.
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.
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.
Closing due to not a Grain issue and inactivity
from grain.
Gonna post the problem on the weekend, didn't have time. Please reopen. Thanks!
from grain.
Okay, thanks for update. Looking forward to hear from you soon
from grain.
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.
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.
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.
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.
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.
Hello @Vlasenko,
thanks for the link, gonna try this. You can close the issue for now.
Cheers,
Christian
from grain.
Related Issues (19)
- Unable to specify proxy for Downloading SetupTools HOT 2
- Huge dependency download time and obsolete dependencies HOT 9
- Portability problems HOT 17
- The option to split Yaml & content HOT 3
- Different `index.html` reference in preview and generate HOT 8
- Crash during preview HOT 1
- Cache Busting HOT 2
- `application.properties` should be optional HOT 7
- `page.url` ignores directory in site url
- Injection declared but never used
- Freezes somewhere inside Ruby on generate
- Java 9 compatibility HOT 1
- Display a nice error for commands instead of a stack trace HOT 2
- Dependency problem HOT 2
- Customizing resource mapping to add new binary types HOT 2
- Help to integrate Jekill module to import wordpress sites HOT 2
- allow SiteConfig to specify attributes for Asciidoctor.convert HOT 3
- StackOverflow during generate HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grain.