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

AVRO-3795: [Java] Raise exception for nonexistent imports in maven-plugin #2334

Merged
merged 4 commits into from
Jul 14, 2023

Conversation

dervan
Copy link
Contributor

@dervan dervan commented Jul 10, 2023

This PR fixes bug reported in https://issues.apache.org/jira/browse/AVRO-3795

Checking if the path exists before processing seems to have no real drawbacks and provides more intuitive behavior, so I think it should be merged. I hope you don't have serious objections.

@github-actions github-actions bot added the Java Pull Requests for Java binding label Jul 10, 2023
Copy link
Contributor

@clesaec clesaec left a comment

Choose a reason for hiding this comment

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

Need to check on getIncludedFiles method (or create a "checkImports" method to run it once)

@@ -213,7 +213,9 @@ public void execute() throws MojoExecutionException {
if (hasImports) {
for (String importedFile : imports) {
File file = new File(importedFile);
if (file.isDirectory()) {
if (!file.exists()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice !!
Same logic should apply to getIncludedFiles method, line 259 ?
(or may be put this control in another method as "checkImportFiles", as it concerns only "imports" variables.

Copy link
Contributor Author

@dervan dervan Jul 13, 2023

Choose a reason for hiding this comment

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

I was considering that, but it seems that if imports field is non-null, then we may be sure that during the execution we will check every imported file in line 216. Indeed, even if getIncludedFiles would execute first, the nonexistent file will be found by line 216 in a next iteration. Do you think it's beneficial to check it anyway in getIncludedFiles?

Copy link
Contributor

@clesaec clesaec Jul 13, 2023

Choose a reason for hiding this comment

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

On line 256, getIncludedFiles method scan for all imports ...

      for (String importFile : this.imports) {
        File file = new File(importFile);
  ...

So, if you have 2 files, and only the first exists, this second method will encountered this unexisting file before the "execute()" method. So, even if used method (isFile & isDirectory) won't fails, i found that checking before using cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course I understand that - I just pointed out that getIncludedFiles touches this file earlier, but with no real downside. Anyway, I moved existence check to the separate method that checks everything in the first place - will that work for you?

<sourceDirectory>${basedir}/src/test/avro</sourceDirectory>
<outputDirectory>${basedir}/target/test-harness/schema</outputDirectory>
<imports>
<import>${basedir}/src/test/avro/nonexistent-dir</import>
Copy link
Contributor

Choose a reason for hiding this comment

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

Check also the case where first file exists (to check getIncludedFiles methods)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added another test for the case where first file exist and the second one doesn't.

Copy link
Contributor

@clesaec clesaec left a comment

Choose a reason for hiding this comment

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

LGTM

@RyanSkraba RyanSkraba merged commit b7023cf into apache:master Jul 14, 2023
12 checks passed
RyanSkraba pushed a commit that referenced this pull request Jul 14, 2023
…ugin (#2334)

* AVRO-3795: [Java] Testcase for nonexistent files in maven-plugin

* AVRO-3795: [Java] Raise exception for nonexistent imports in maven-plugin

* AVRO-3795: [Java] Fix testcases for nonexistent files in maven-plugin

* AVRO-3795: [Java] Check imports for maven-plugin in separate method
RanbirK pushed a commit to RanbirK/avro that referenced this pull request May 13, 2024
…ugin (apache#2334)

* AVRO-3795: [Java] Testcase for nonexistent files in maven-plugin

* AVRO-3795: [Java] Raise exception for nonexistent imports in maven-plugin

* AVRO-3795: [Java] Fix testcases for nonexistent files in maven-plugin

* AVRO-3795: [Java] Check imports for maven-plugin in separate method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java Pull Requests for Java binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants