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

Validates the file path of a TexGroup and fixes Texgroup's "Library has been modified by another program" #6586

Merged

Conversation

systemoperator
Copy link
Contributor

@systemoperator systemoperator commented Jun 4, 2020

Fixes #6420.
Fixes #6585.

  • Change in CHANGELOG.md described (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Hi @systemoperator , thanks again for this PR and your work here.
I got some remarks about the codestyle and one suggestion with StringUtils.

CHANGELOG.md Outdated Show resolved Hide resolved
@systemoperator
Copy link
Contributor Author

I don't know where to put import org.apache.logging.log4j.core.util.FileUtils;. Wherever I put it, checkstyle fails.

@Siedlerchr
Copy link
Member

@systemoperator We have our own FileUtil class in model or logic, beware of the import.

@calixtus
Copy link
Member

calixtus commented Jun 5, 2020

Checkstyle is failing because of now unused import io.file.

@systemoperator systemoperator changed the title Validates the file path of a TexGroup Validates the file path of a TexGroup and fixes Texgroup's "Library has been modified by another program" Jun 5, 2020
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Great! Looks good to me!

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 5, 2020
@systemoperator
Copy link
Contributor Author

Apparently, this PR also fixes #6394. At least I could not reproduce it so far. I will test it onwards.

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.

Thanks for your PR!

Just to make sure that I understand the changes correctly: the issue is fixed by parsing the groups last?

I have to minor comments concerning the code. It would be nice if you could also add a test so that we don't break it in the future again (especially since this concerns the parser of bib files, which is arguely the most important part of JabRef).

@tobiasdiez tobiasdiez added the status: changes required Pull requests that are not yet complete label Jun 5, 2020
@systemoperator
Copy link
Contributor Author

systemoperator commented Jun 5, 2020

Just to make sure that I understand the changes correctly: the issue is fixed by parsing the groups last?

Yes, because the groups access data which need to be defined beforehand. Depending on the sequence in the entry set, this may work once but not every time.

@systemoperator
Copy link
Contributor Author

systemoperator commented Jun 5, 2020

Now without stream.^^

Any suggestion how to test the case mentioned at #6586 (review)?

@tobiasdiez
Copy link
Member

The code looks good to me! For the test, it should be similar to the following:

@Test
void integrationTestGroupTree() throws IOException, ParseException {
ParserResult result = parser.parse(new StringReader("@comment{jabref-meta: groupsversion:3;}" + OS.NEWLINE
+ "@comment{jabref-meta: groupstree:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE
+ "1 KeywordGroup:Fréchet\\;0\\;keywords\\;FrechetSpace\\;0\\;1\\;;" + OS.NEWLINE
+ "1 KeywordGroup:Invariant theory\\;0\\;keywords\\;GIT\\;0\\;0\\;;" + OS.NEWLINE
+ "1 ExplicitGroup:TestGroup\\;0\\;Key1\\;Key2\\;;" + "}"));
GroupTreeNode root = result.getMetaData().getGroups().get();
assertEquals(new AllEntriesGroup("All entries"), root.getGroup());
assertEquals(3, root.getNumberOfChildren());
assertEquals(
new RegexKeywordGroup("Fréchet", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, "FrechetSpace", false),
root.getChildren().get(0).getGroup());
assertEquals(
new WordKeywordGroup("Invariant theory", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, "GIT", false, ',', false),
root.getChildren().get(1).getGroup());
assertEquals(Arrays.asList("Key1", "Key2"),
((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys());
}

Create the string by hand (with groups before the other setting that makes troubles) and then verify that the groups in the parsed metadata has the valid data.

@systemoperator
Copy link
Contributor Author

The test was a bit tricky (access real file, relative, user name, hostname, ...), but it works now.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Code looks good; did not test it though.

Have some code nitpicks. Hope, you like these suggestions (moving the code to more modern Java 14).

default:
// Keep meta data items that we do not know in the file
metaData.putUnknownMetaDataItem(entry.getKey(), value);
} else if (entry.getKey().equals(MetaData.SAVE_ACTIONS)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep the switch (entry.getKey) somehow? Maybe nested in an else branch?

You can use the new Java14 switch: https://openjdk.java.net/jeps/361

(File needs to be added to

<property name="fileNamePattern" value="AuthorAndsReplacer.java|Ordinal.java|EntryTypeView.java" />
then)

Copy link
Member

Choose a reason for hiding this comment

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

This is still a huge p.i.t.a.
Checkstyle really needs to keep up, people start getting tired of these workarounds.
Some background information, if you are interested: checkstyle/checkstyle#6615

Copy link
Member

Choose a reason for hiding this comment

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

The key problem is here that switch cases are not executed in order. That's the reason for the if else

Copy link
Member

Choose a reason for hiding this comment

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

In the concrete case here, it is always checked for entry.getKey(). Please check the diff:

grafik

The wrong order was at that diff - completely unrelated to my proposal!

grafik

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the switch statement could be reintroduced (and simplified). Before this fix, the code was structured really confusing and looked error-prone. So I decided to create this consistent and simplified version, which I find quite acceptable.

Copy link
Member

Choose a reason for hiding this comment

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

I meant only for the lower part; not with the xxxx continue statements. Just for the endless chain of else if (entry.getKey().equeals(MetaData.X)) chains, where only X is different from the checks.

There is ALWAYS entry.getKey() compared from line 75 to line 92 (or did I see something wrong?).

This is just a matter of taste. Maybe, I'll just do it and open another PR to have the discussions there. Should not be a show stopper for us now.

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 16, 2020
input -> {
if (StringUtil.isBlank(input)) {
return false;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

@stefan-kolb Would review here: "Fail fast". Not endless nested if/else statements, but just exit early.

Therefore, I proposed:

if (StringUtil.isBlank(input)) {
  return false;
}

Think, I will start another PR with this and the other code style thing and we can have the discussion there --> we need to get this fix in soon.

@koppor koppor merged commit ef0a6bb into JabRef:master Jun 17, 2020
Siedlerchr added a commit that referenced this pull request Jun 20, 2020
* upstream/master:
  Validates the file path of a TexGroup and fixes Texgroup's "Library has been modified by another program" (#6586)
  Bump postgresql from 42.2.12 to 42.2.14 (#6610)
  Add markdown-link-check (#6542)
  Catch InaccessibleObjectException (#6519)
  Fix author formatter for unchanged names (#6552)
  Bump com.simonharrer.modernizer from 1.8.0-1 to 2.1.0-1
  Bump org.beryx.jlink from 2.19.0 to 2.20.0
  Bump classgraph from 4.8.83 to 4.8.86
  Update FileUtilTest.java
  Update FileUtilTest.java
  Squashed 'src/main/resources/csl-styles/' changes from c5f14e2..716f635
  Update FileUtilTest.java
  Update MoveFilesCleanupTest.java
  checkstyle
  Fix dowmloaded files moved to citaiton key dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
5 participants