Fixes when dealing with unusual properties files and other edge-cases. - #67
nx-eric-jarosch wants to merge 4 commits into
Conversation
# Conflicts: # src/main/java/org/codejive/properties/Properties.java
- Properties#put no longer crashes when the last property is at the end of the file and has no value - Properties#put inserts the correct amount of blank lines when the file contains no properties but some number of comments. - Properties#load no longer swallows the last key if it has no value. - Cursor#add skips the inserted item when there are no tokens (matching the behaviour seen when there are tokens) - Cursor#addToken now uses the correct index when checking Cursor#hasToken. Thus the line is inserted in the expected position, instead of at the end of the file.
|
There's some good stuff in here, but separate issues should ideally be split up into several PRs. Even if it's just a small fix like |
|
I ended up pulling in #65 because the failing tests made it hard to tell if I broke things, or if things were already broken. Do you have some tips for how to deal with PRs that build ontop of each other? |
|
First I'd separate things that don't have anything to do with each other and don't affect one another. So you could have one PR that says "fixing compiler warnings". It won't affect any other PRs so it doesn't matter if it gets merged first or last or never. Then I'd start again with a fresh start without any of the changes you just made and make another PR saying something like "Fixing crLf test". Same thing, it doesn't affect any other PRs. The change in encoding, is an especially good example of having as a separate PR, because even though it's a tiny change it can possibly affect a lot of things. (Encodings always cause trouble) So it might need specific new tests to make sure we didn't break anything with that change. Now, the moment you want to create a PR that depends on another PR I'd just continue work from that PR and then , when you're done, create a new PR and mention in the description that it needs the other PR to be merged first. BUt honestly I'd only do that when they are complex changes that you really want to separate. If not, just make it a single PR. In all these cases branches are your friends. With each PR you want to create you first go back to the clean state |
|
Btw @nx-eric-jarosch I created my own PR to fix the newline issue, because when looking into your changes I found a much bigger problem, there was an actual bug in the code. So I fixed that which also includes your changes (see #69). |
Properties#put no longer crashes when the last property is at the end of the file and has no value
Example
foo=or
would previously result in an
IllegalStateExceptionwhen callingProperties#put()Properties#put inserts the correct amount of blank lines when the file contains no properties but some number of comments.
Example
Properties#load no longer swallows the last key if it has no value.
Example
resulted in a Properties Object with no entries.
See also: #66
Cursor#add skips the inserted item when there are no tokens (matching the behaviour seen when there are tokens)
Previously this would, for example, cause this:
to store the tokens in the wrong order:
tokens = [ SEPARATOR, KEY ]Cursor#addToken now uses the correct index when checking Cursor#hasToken. Thus the line is inserted in the expected position, instead of at the end of the file.
Example
Changes inherited from #65
Corrections of Tests
testLoadCrLf@TestannotationrawValuesandrawEntrySetcorrectly return the\r\nas contained in the test file, but the test expected\n.readAll()currently assumes thatCharset.defaultCharset()returns UTF-8.That is not the case on my system (or on Windows, in general?). Instead it is
windows-1252.The fix is to make this assumption explicit.
Resolved Warnings in Tests
testRemoveMiddleIteratoruses a rawIterator, the generic type is known to beStringat compile time.testInteropPutLoad()does not throwURISyntaxException, removed.