-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix: fix exception in custom preview layout change #7539
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f796415
fix: for issue 7526
yinpeiqi 08027e6
rollback: unset flag setting
xiongz-c 7009f35
add try-catch to avoid throw error when user typing and add valid che…
xiongz-c cfc074d
Merge branch 'master' into fix-for-issue-7526
xiongz-c c5af0a1
code style check
xiongz-c 24b24d5
Merge branch 'fix-for-issue-7526' of github.com:yinpeiqi/jabref into …
xiongz-c 47352ab
remove some duplicate code
xiongz-c 158fda7
check changlog format
xiongz-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,6 +260,7 @@ private void parseField() throws IOException { | |
} | ||
throw new StringIndexOutOfBoundsException( | ||
"Backslash parsing error near \'" + lastFive.toString().replace("\n", " ") + '\''); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not add an empty line |
||
} | ||
|
||
if ("begin".equalsIgnoreCase(name)) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching runtime excpetions is a very bad thing. Where exactly is the
StringIndexOutOfBoundsException
thrown? Exceptions should be catched as early as possible.In this case, it is thrown at
parse()
in LayoutHelper.java line 191.The real fix is that
org.jabref.logic.layout.LayoutHelper#getLayoutFromText
should returnOptional<Layout>
and not throw any exception.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, sir. I am also following this issue. Do you think this exception
StringIndexOutOfBoundsException
is unnecessary? ThisStringIndexOutOfBoundsException
will be thrown when '\' is entered(in editing stage).What if it's in the saving stage? If user click the
save
button, and there is only a '\', should the exception still be thrown?If we do not throw any exception, the user may not be aware that there is a wrong '\'. If you insist that throwing no exception is a better choice, I can help you implement it. Don't worry about @yinpeiqi and @zc-BEAR. I have communicated with them. Looking forward to your reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After my investigation,
Layout
could not be null. ThereforeLayoutHelper#getLayoutFromText
seems not effective. In my opinion, we can delete the codethrow new StringIndexOutOfBoundsException( "Backslash parsing error near \'" + lastFive.toString().replace("\n", " ") + '\'');
inLayoutHelper#parseField
.I also found that
Layout
's constructor will warn "Nested field/group entries are not implemented!" in logger if the user input's invalid. In this case, does the error message need to be presented to the user? @kopporThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about
Layout
beingnull
, its about getting rid of the exception. Using exceptions for control flow is a bad thing (see also Java-by-Comparison). Please refactorLayoutHelper
not to throw any exception atparse()
orgetLayoutFromText()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EricLee543 I am not sure how to present that to the user. In the long run, we should switch to Apache Velocity as this shifts maintenance effort from JabRef to another project. See https://github.com/koppor/jabref/issues/392 for details.