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

NPE for some styles #116

Closed
Siedlerchr opened this issue Jan 16, 2022 · 4 comments
Closed

NPE for some styles #116

Siedlerchr opened this issue Jan 16, 2022 · 4 comments
Assignees

Comments

@Siedlerchr
Copy link
Contributor

Originally reported here with some styles JabRef/jabref#8421

I could reproduce it (e.g. Oxford Art Journal). The preview uses the Test Entry:
https://github.com/JabRef/jabref/blob/bb011c9313367a28990ae213b3920fe6cd10d1dc/src/main/java/org/jabref/logic/util/TestEntry.java#L16-L39

Error while generating citation style
java.lang.NullPointerException: Cannot invoke "de.undercouch.citeproc.csl.internal.SBibliography.render(de.undercouch.citeproc.csl.internal.RenderContext)" because the return value of "de.undercouch.citeproc.csl.internal.SStyle.getBibliography()" is null
	at [email protected]/de.undercouch.citeproc.CSL.makeBibliography(Unknown Source)
	at [email protected]/de.undercouch.citeproc.CSL.makeBibliography(Unknown Source)
	at [email protected]/org.jabref.logic.citationstyle.CSLAdapter.makeBibliography(Unknown Source)
	at [email protected]/org.jabref.logic.citationstyle.CitationStyleGenerator.generateCitations(Unknown Source)
	at [email protected]/org.jabref.logic.citationstyle.CitationStyleGenerator.generateCitation(Unknown Source)
	at [email protected]/org.jabref.logic.citationstyle.CitationStylePreviewLayout.generatePreview(Unknown Source)
	at [email protected]/org.jabref.gui.preview.PreviewViewer.lambda$update$4(Unknown Source)
	at [email protected]/org.jabref.gui.util.BackgroundTask$1.call(Unknown Source)
	at [email protected]/org.jabref.gui.util.DefaultTaskExecutor$1.call(Unknown Source)
	at [email protected]/javafx.concurrent.Task$TaskCallable.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

@michel-kraemer
Copy link
Owner

Thanks for reporting this! The styles mentioned in the JabRef issue do not contain instructions to format bibliographies. It seems they're only used to format citations.

A NullPointerException is of course not very helpful in this case. What would you suggest instead? IllegalArgumentException? IllegalStateException? Maybe a method to determine if a style can be used to format bibliographies, which you can use upfront to filter out the styles that would not work anyhow? (e.g. CSL.canFormatBibliographies(style), plus maybe CSL.canFormatCitations(style))

@Siedlerchr
Copy link
Contributor Author

Ah thanks for the info, didn't know there was as difference.
I guess a method like CSL.canFormatBibliographies(style) would be ideal, so we can filter them out. Preferable over an exception.

@michel-kraemer
Copy link
Owner

I've checked the CSL specification and the <cs:citation> element is mandatory, whereas <cs:bibliography> is optional. This means it is OK to only add canFormatBibliographies(). canFormatCitations() is not necessary. I just pushed a commit with this change. I also made sure makeBibliography throws an IllegalStateException (instead of an NPE) with a sensible message if the style does not support formatting bibliographies.

@Siedlerchr
Copy link
Contributor Author

Thanks a lot!

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

No branches or pull requests

2 participants