Better docs in IOUtils and IOUtils.byteArray(int size)#374
Better docs in IOUtils and IOUtils.byteArray(int size)#374garydgregory merged 15 commits intoapache:masterfrom
Conversation
…ize is legal(size > 0), the illegal(size <=0) should throw IllegalArgumentException.
| bytes = IOUtils.byteArray(size); | ||
| }catch (Exception e) { | ||
| assertEquals(e.getClass().getName(), IllegalArgumentException.class.getName()); | ||
| } |
There was a problem hiding this comment.
I think instead it could use JUnit's @Test(expected=IllegalArgumentException.class), or assertThrows.
There was a problem hiding this comment.
And I think when the first exception happens, the second is part of the test is never executed? Probably needs to be broken down into two separate tests, maybe with @ParameterizedTest too.
There was a problem hiding this comment.
ok, I changed IOUtilsTest.testByteArrayWithIllegalSize() with @ParameterizedTest.
you can review the code.
There was a problem hiding this comment.
Why would we trade a more vague exception when the JVM throws a more precise and quite specific exception? Maybe this issue can be simplified with better Javadoc? This PR would also introduce an inconsistency since other places would throw the JVM exception.
There was a problem hiding this comment.
Hi garydgregory,
Thank you for your good suggestion, I updated the doc and changed the unittest, you can review it again.
There was a problem hiding this comment.
In order to improve my work efficiency,I will study github workflow in the next week.
| * @param size array size. | ||
| * @return a new byte array of the given size. | ||
| * | ||
| * @exception IllegalArgumentException If {@code size <= 0} |
| * Instances should NOT be constructed in standard programming. | ||
| * @deprecated Will be private in 3.0. | ||
| */ | ||
| @Deprecated |
There was a problem hiding this comment.
This is doing more than what's described in the PR title. Maybe worth moving to a separate PR to make it easier to track in the changelog.
There was a problem hiding this comment.
Thx, I will rollback it
There was a problem hiding this comment.
Can you remove this deprecation as @kinow requested?
There was a problem hiding this comment.
Wait... this deprecation is fine. It's slightly out of scope for the PR but it's fine.
| * Instances should NOT be constructed in standard programming. | ||
| * @deprecated Will be private in 3.0. | ||
| */ | ||
| @Deprecated |
There was a problem hiding this comment.
Should this @Deprecated be removed? There was a comment to remove a different @Deprecated but this one should be kept.
There was a problem hiding this comment.
-1: Don't remove this tag,
There was a problem hiding this comment.
this is not resolved - you have still removed a comment that was in the code before - can you put it back?
There was a problem hiding this comment.
The @deprecated tag should NOT be removed.
There was a problem hiding this comment.
Hi All,
sorry for my error operation, I fixed the doc and add @deprecated tag about FileUtils.
public FileUtils() { //NOSONAR
|
|
||
| /** | ||
| * Returns a new byte array of the given size. | ||
| * Throws java.lang.NegativeArraySizeException if the size is negative. |
There was a problem hiding this comment.
This is in the wrong place, use a throws tag.
There was a problem hiding this comment.
Hi garydgregory,
I fixed it with @throws, you can review it again.
| @Test | ||
| public void testByteArrayWithNegativeSize() { | ||
| int size = -1; | ||
| assertThrows(NegativeArraySizeException.class,() -> { |
There was a problem hiding this comment.
You can just say assertThrows(NegativeArraySizeException.class,() -> IOUtils.byteArray(-1)); but I am not even sure we should have this test since it does not improve our code coverage, it just test what the JVM does. @kinow , any thoughts?
There was a problem hiding this comment.
Hi garydgregory,
from your comments, I checked the code and fixed again, you can review it again.
Thanks.
garydgregory
left a comment
There was a problem hiding this comment.
Hello @ArdenL-Liu
Thank you for the PR, please see my comments.
Codecov Report
@@ Coverage Diff @@
## master #374 +/- ##
============================================
- Coverage 85.71% 85.63% -0.09%
Complexity 3101 3101
============================================
Files 204 204
Lines 7365 7365
Branches 904 904
============================================
- Hits 6313 6307 -6
- Misses 804 811 +7
+ Partials 248 247 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| * | ||
| * @param size array size. | ||
| * @return a new byte array of the given size. | ||
| * @throws NegativeArraySizeException if the size is negative. |
There was a problem hiding this comment.
This PR seems ok to me now except for this addition. We do not document this type of JVM exception anywhere else IIRC. If we were to doc this, then it would make sense to doc all callers as well, then this would touch almost everything which would not help anyone IMO.
There was a problem hiding this comment.
As yours, this is why I want to add throws NegativeArraySizeException tag to this method, In fact, in order to help users to use and understand these methods, I think we should add it to the doc of all the methods like it.
Of course , we can add the parameters validation to the head position of the method's logic. some methods do it, such as : read(...., int), skip(... ,int).
| */ | ||
| package org.apache.commons.io; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
There was a problem hiding this comment.
Remove noise in the PR: There is no need to update these imports.
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
| import static org.junit.jupiter.api.Assertions.*; |
|
FYI: I've handled the Javadoc "java.lang" issue separately throughout most Apache Commons components. |
|
@ArdenL-Liu |
|
Hi garydgregory, |
IOUtils.byteArray(int size) add the verification to assure that the size is legal(size > 0), the illegal(size <=0) should throw IllegalArgumentException.