-
Notifications
You must be signed in to change notification settings - Fork 220
Cleanup read and write bytes in test & pom improvements #727
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
Draft
leerho
wants to merge
8
commits into
main
Choose a base branch
from
Fix_get_file_bytes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+595
−462
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e693cfa
This replaces a bunch of methods attempting to read file bytes with one
leerho 31e5942
Fix unread var.
leerho d6a9d04
Add putBytesToFile methods
leerho 3f8eb8e
Fix get_file_bytes and put_file_bytes.
leerho f054e51
Update pom.
leerho 1e1bd36
update testng.xml
leerho 008109e
update pom.
leerho 896d02a
try to fix pom.xml
leerho 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
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/test/java/org/apache/datasketches/common/A_BeforeSuite.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.datasketches.common; | ||
|
|
||
| import org.testng.annotations.BeforeSuite; | ||
|
|
||
| public class A_BeforeSuite { | ||
|
|
||
| @BeforeSuite | ||
| public void printTestEnvironment() { | ||
| System.out.println("===================================================="); | ||
| System.out.println("TEST JDK: " + System.getProperty("java.version")); | ||
| System.out.println("TEST JDK HOME: " + System.getProperty("java.home")); | ||
| System.out.println("====================================================="); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning test
Copilot Autofix
AI 1 day ago
In general, to fix this type of issue you must ensure that any variable dereferenced in a
catch/error path is definitely non-null on all paths, or guard the dereference with an explicit null check or a safe fallback value. Logging or message construction should not itself depend on state that may not have been initialized due to the very failure being reported.For this specific case, the best fix without changing functionality is to avoid dereferencing
filePathwhen it may benull. Instead of callingfilePath.toString()in the error message, we can build the message from values that are always available:basePathandfileName, both of which are validated as non-null at the top of the method. We can simply replace"System IO Error writing file: " + filePath.toString() + " " + ewith"System IO Error writing file: " + basePath.resolve(fileName) + " " + e. This usesbasePath.resolve(fileName)again purely for string construction; even if that throws, it would be anotherRuntimeExceptionbeing thrown from within thecatch, which is acceptable and does not reintroduce a null dereference. Alternatively, we could fall back to a literal that indicates an unknown path, but usingbasePathandfileNamepreserves nearly identical functionality.Only the
catchblock inputFileBytes(lines 135–137) ofsrc/test/java/org/apache/datasketches/common/TestUtil.javaneeds to change. No new imports or methods are required.