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

date field with non date data generates error #8747

Closed
2 tasks done
ilippert opened this issue May 2, 2022 · 19 comments · Fixed by #9365
Closed
2 tasks done

date field with non date data generates error #8747

ilippert opened this issue May 2, 2022 · 19 comments · Fixed by #9365
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs entry-editor

Comments

@ilippert
Copy link
Contributor

ilippert commented May 2, 2022

JabRef version

Latest development branch build (please note build date below)

Operating system

GNU / Linux

Details on version and operating system

JabRef 5.6--2022-04-25--5c9d898 Linux 5.17.4-200.fc35.x86_64 amd64 Java 17.0.2 JavaFX 18+12

Checked with the latest development build

  • I made a backup of my libraries before testing the latest development version.
  • I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

  1. generate new entry
  2. enter non date data in date field, e.g. an b

Appendix

...

Log File
java.lang.NullPointerException: Cannot invoke "java.time.temporal.TemporalAccessor.query(java.time.temporal.TemporalQuery)" because "<parameter1>" is null
	at org.jabref@5.6.60000/org.jabref.gui.util.component.TemporalAccessorPicker.getLocalDate(Unknown Source)
	at org.jabref@5.6.60000/org.jabref.gui.util.component.TemporalAccessorPicker$InternalConverter.fromString(Unknown Source)
	at org.jabref@5.6.60000/org.jabref.gui.util.component.TemporalAccessorPicker$InternalConverter.fromString(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.control.DatePicker.commitValue(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.control.DatePicker.lambda$new$2(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Node$FocusedProperty.notifyListeners(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene$12.invalidated(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene$KeyHandler.setFocusOwner(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene$KeyHandler.requestFocus(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene.requestFocus(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Node.requestFocus(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.mousePressed(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.scene.control.inputmap.InputMap.handle(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.event.Event.fireEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene$MouseHandler.process(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene.processMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.glass.ui.View.notifyMouse(Unknown Source)
	at org.jabref.merged.module@5.6.60000/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at org.jabref.merged.module@5.6.60000/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

@ThiloteE
Copy link
Member

ThiloteE commented May 3, 2022

b like in 10 000 bc?

@ilippert
Copy link
Contributor Author

ilippert commented May 3, 2022

well, maybe wrongly, I have been using the date field for information, too, like \autocap{f}orthcoming. So, the b was just to illustrate the non-date format.

@Siedlerchr
Copy link
Member

As far as I remember, if you want to put in dates other than in the iso8601 format in that field, you have to use the way around the bibtex editor.
There should be a check preventing the date picker to popup for

@ilippert
Copy link
Contributor Author

ilippert commented May 4, 2022

I believe that in earlier nightly versions I did not received an error message when entering non iso8601 data in that field.

@LIM0000
Copy link
Contributor

LIM0000 commented May 5, 2022

Hi, I have found that this issue is due to

  1. null return from LocalDateTime.parse() if the text cannot be parsed.
@Override
public TemporalAccessor fromString(String value) {
        return LocalDateTime.parse(value, defaultFormatter);
}
  1. dateTime will then be assigned with null from the parse function.
TemporalAccessor dateTime = getStringConverter().fromString(value);
temporalAccessorValue.set(dateTime);
return getLocalDate(dateTime);
  1. In getLocalDate(), no validation for dateTime before .query() is called.
private static LocalDate getLocalDate(TemporalAccessor dateTime) {
        // Try to get as much information from the temporal accessor
        LocalDate date = dateTime.query(TemporalQueries.localDate());
        if (date != null) {
            return date;
        }

        try {
            return YearMonth.from(dateTime).atDay(1);
        } catch (DateTimeException exception) {
            return Year.from(dateTime).atDay(1);
        }
    }


Possible solution:
We could add a validation for dateTime before it is called to fix the error.

if (dateTime == null) {
    return null;
}


Hope this is helpful.

@Siedlerchr
Copy link
Member

Siedlerchr commented May 6, 2022

@LIM0000 Thanks for looking into this. As I was recently working on the DateTimeFormatter stuff for imports, I rememebred that we have this Date.parse class (from org.jabref.model.entry;)
which supports a lot more pattern. Maybe that can be reused here?

See also the TemporalAccessorPicker

@Siedlerchr Siedlerchr added the bug Confirmed bugs or reports that are very likely to be bugs label May 6, 2022
@LIM0000
Copy link
Contributor

LIM0000 commented May 7, 2022

@Siedlerchr Thank you for your comment.
I have looked into this issue again and come up with a possible solution.

Proposal solution

If user's input cannot be converted from String to LocalDate by LocalDate.parse(), a dialog box pops up to inform user that the date pattern is unrecognizable. Previous date info will be restore in date field if there is any. Downside of this solution is that user not able to store any non date data into date field. Should we allow user to store non date input into date field?

I have also tried to look into Date.parse (from org.jabref.model.entry.Date) and could confirm that LocalDateTime.parse(value, defaultFormatter) could cover all patterns (in org.jabref.model.entry.Date) class.

@ilippert
Copy link
Contributor Author

ilippert commented May 7, 2022 via email

@ThiloteE
Copy link
Member

ThiloteE commented May 7, 2022

There is a tradeoff between:

  1. Standard info in date field
    • preventing typos
    • educates users about ISO / BibLaTeX date/time format.
  2. having non-standard information in the date field.
    • allows users to do "special things".

@ilippert I am not quite sure what prevents you from creating new custom fields like "forthcoming" or "submitted"? (I know you already have some custom fields and know how to do it). Would that not be a workaround? Is it because these new custom fields are not detected by standard citation styles and you would want them to show in your final document? Sorry, just curious.

@ThiloteE
Copy link
Member

ThiloteE commented May 7, 2022

related: #2753

@Siedlerchr
Copy link
Member

Siedlerchr commented May 7, 2022

I agree with @ThiloteE here. This information should NOT belong in the date field. for example for the status there are extra fields 4.9.2.11 Publication State, biblatex manual

inpreparation The expression ‘in preparation’ (the manuscript is being prepared for publication).
submitted The expression ‘submitted’ (the manuscript has been submitted to a journal or
conference).
forthcoming The expression ‘forthcoming’ (the manuscript has been accepted by a press or
journal).
inpress The expression ‘in press’ (the manuscript is fully copyedited and out of the author’s
hands; it is in the final stages of the production process).
prepublished The expression ‘pre-published’ (the manuscript is published in a preliminary form or
location, such as online version in advance of print publication).

@ThiloteE
Copy link
Member

ThiloteE commented May 7, 2022

Ah, Christoph, I do not have an opinion on this yet xD I just wanted to mention the tradeoff and was curious if this could be solved with a workaround. I was not aware forthcoming, submitted etc. are supported by biblatex.

What do you mean with "this information should belong in the date field"? - What info exactly?

@Siedlerchr
Copy link
Member

I meant "NOT". Edited my comment.

@LIM0000
Copy link
Contributor

LIM0000 commented May 9, 2022

Thank you for the comments.
May I ask that any action needed for this issue?
For example, a popup dialog informs user that date field does not accept non date data, please input valid date format.

@ilippert
Copy link
Contributor Author

ilippert commented May 9, 2022

Hi, ok, just looked at the biblatex and biblatex-chicago manuals. The latter also prefers like the biblatex manual the use of pubstate for information like inpress. However, it also notes the possibility to add in year \autocap{f}orthcoming (which is something I had "inherited").

Anyway, moving forward, I think for the date field:

  • either non standard information should be gracefully accepted OR
  • if non-standard date information is provided, a date-picker should be provided.

However, as a user, I want to be free to add, say, something like 2008 or 10 BC (because I only have that information) or forthcoming in the date field, even if that is not recommended.

So, the first option is that JabRef trusts the user that they know what they want to input, while the second option risks forcing a date on the user, while the user might not want a full date at all.

@claell
Copy link
Contributor

claell commented May 9, 2022

There are options in between, I'd say. So maybe inform the user that the action they are trying to do is not recommended and allow them to proceed anyway after acknowledging this. (If there are really use cases where this option is needed and that are acceptable)

@ilippert
Copy link
Contributor Author

ilippert commented May 9, 2022

Well, maybe far too demanding, but a great popup would consist of

  • date/year/month selector, allowing "partial" date information (which, in my experience is the normal; I rarely ever have a full date of the publication)
  • a dropdown menu with the known/available pubstates; and a "custom text" option

@huangderek02
Copy link

Hi @ilippert , can you please assign me this issue?

@Siedlerchr
Copy link
Member

Siedlerchr commented Nov 8, 2022

The issue is now fixed and as a side effect the chooser also can display negative dates (BC)
(Some more info https://www.tondering.dk/claus/cal/iso8601.php)

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs entry-editor
Projects
Archived in project
6 participants