Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix export and import of MS office day/year/month acessed fields #2862

Merged
merged 4 commits into from
May 24, 2017

Conversation

Siedlerchr
Copy link
Member

Fix possible NPE in Date parsing
Fixes #2859

  • Change in CHANGELOG.md described
  • Tests created for changes
    - [ ] Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
    - [ ] If you changed the localization: Did you run gradle localizationUpdate?

@Siedlerchr Siedlerchr added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers component: export-or-save labels May 23, 2017
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me in general and I have only two smaller remarks. Can be merged after they are fixed.

}
Optional<Date> parsedDateAcesseField = Date.parse(dateAccessed);
String yearAccessed = parsedDateAcesseField.flatMap(Date::getYear).map(accYear -> accYear.toString())
.orElse(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using null strings, I would prefer if you use the ifPresent method (since we probably don't want to add fields with null as value anyway).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null values are an indicator that no value is present, and in this case it is consistent to the rest of the code. In the addField method there is already a check if( value == null ) return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I also don't like the rest of the code exactly for this reason. But instead of rewriting everything I would vote for an incremental improvement and since you already converted parts to use optionals... (By the way, BibEntry has the distinction between setField and clearField precisely on similar grounds.)

return Optional.of(new Date(parsedDate));
} catch (DateTimeParseException ignored) {
// Ignored
if (dateString != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that null is a valid argument. We try to get rid of null values and should be consistent here. Either way, if(StringUtil.isBlank(dateString)) return Optional.empty(); is probably preferable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we do a Objects.requireNonNull and leave the checking to the caller, or we use this isBlank Method. Currently it will throw an NPE from the TemporalAccessor.parse method if null is passed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for throwing NPE to be consistent with the TemporalAccesor.parse method.

@tobiasdiez tobiasdiez removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 23, 2017
@Siedlerchr
Copy link
Member Author

Change the code to optionals. Merge it in now

@Siedlerchr Siedlerchr merged commit 19f1796 into master May 24, 2017
@Siedlerchr Siedlerchr deleted the msoffice-acessed branch May 24, 2017 12:27
Siedlerchr added a commit that referenced this pull request May 27, 2017
* upstream/master: (23 commits)
  Implement #2785: resort groups using drag & drop (#2864)
  Add Library of Congress as ID-fetcher (#2865)
  Fix export and import of MS office day/year/month acessed fields (#2862)
  Adsurl to url (#2861)
  Update LICENSE.md
  Update
  Update LICENSE.md
  Update license file so that github recognize it properly
  Improve Issue Template Using a Collapsible Log Area
  Fix #2852: Improve performance of group filtering.
  Rename GroupSelector to GroupSidePane
  Fix #2843: Show information correctly in entry editor
  Remove old entry editor code related to focus selection
  Implement feedback
  Menu Greek Translation (#2836)
  Relaxed the regex to also match negative timezone formats when parsing pdf annotation dates (#2841)
  Update localization
  Remove unnecessary group code (and move remaining settings to preferences)
  Add Local Maven repo as first lookup resource, to avoid having duplicate libs in gradle and maven
  Implement #2786: Allow selection of multiple groups
  ...
Siedlerchr added a commit that referenced this pull request Jun 3, 2017
* upstream/master: (38 commits)
  Add link to "feature branch workflow"
  Support Annotations Created by Foxit (#2878)
  Fixes jacoco by excluding the fetcher tests from analysis (#2877)
  Fix entry editor (#2875)
  update bcprov-jdk15on from 1.56 -> 1.57
  update assertj-swing-junit from 3.5.0 -> 3.6.0
  update mockito-core from 2.7.22 -> 2.8.9
  update jfx from 0.11.0 -> 0.11.1
  update google guava from 21.0 -> 22.0
  Fix Divide by zero exception if rows is zero in Entry Editor Tab (#2873)
  Implement #2785: resort groups using drag & drop (#2864)
  Add Library of Congress as ID-fetcher (#2865)
  Fix export and import of MS office day/year/month acessed fields (#2862)
  Adsurl to url (#2861)
  Update LICENSE.md
  Update
  Update LICENSE.md
  Update license file so that github recognize it properly
  Improve Issue Template Using a Collapsible Log Area
  Fix #2852: Improve performance of group filtering.
  ...
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants