-
Notifications
You must be signed in to change notification settings - Fork 100
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
Why would we get 'Cannot invoke "java.io.File.toURI()" because "file" is null' from Maven plugin? #582
Comments
I think one cause could be the You could also safely remove Regards |
See issue #443 for change regarding |
Changing the specVersion to 3.0 made no difference. Same error. |
Could you then send the output with mvn |
Looking at this output, it might confirm a thought I was having. The source directory has a wsdl, and a bunch of xsd files, which I assume are referenced directly or indirectly from the wsdl. If the developer had left one or more required schema files out of this, would it produce that error? I have no idea whether this is what happened, I'm just looking at hypotheses. |
The NPE is quite specific in some location. I've seen this output in your mvn run :
Could you please try to fix this relocation to see if this fixes your issue ? |
That is not an error. That has been like that for a long time. It is still downloading the relocated artifact. And none of our poms are even referencing that old path, so I don't know where that is coming from. The effective pom doesn't show that. |
Sorry but without MRE, it's try-and-error guessing. Analysis pointed out the usage of
You should use latest version of jaxb-plugins regarding migration guide <groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
<version>4.0.8</version> <!-- same version as jaxb-maven-plugin --> If using <groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-runtime</artifactId>
<version>4.0.8</version> <!-- same version as jaxb-maven-plugin --> |
I'm not certain exactly what changes are implied, but I just tried the following:
It had no effect. Same error. |
On the hypothesis that the developer somehow left off one or more schema files, I tried searching for ":include" in all the existing wsdl and xsd files in that directory and verifying each one, and each referenced file does exist in that directory. |
Could you please share MRE so that I can debug it ? Thanks |
And also could you share the last working configuration you had ? Thanks |
Providing the MRE would be impossible, and not just for security. There are many dependent components. |
Could you then share the latest working config you had please ? |
You weren't asked to share your project but rather a Minimal Reproducible Example, otherwise, as @laurentschoelens already said, it is not possible to help in any way.
And you are the only one who would be able to reduce the problem to its core. |
So can someone help me through getting my local environment set up so that I can debug this myself? I've been writing and debugging Java code for many years, but I've never worked on a Maven plugin. |
What I could say for sure is that removing the xjc plugins should fix the issue. Here we have a resolved artefact (by transitivity) that has a null file returned. One thing that could be done is logging the error and ignore it but... I'd like to reproduce the error first in order to understand why you face this issue first. The main branch can be build safely with jdk11 as minimal jdk version. |
By "removing the xjc plugins", do you mean not using "jaxb-plugins" or "jaxb2-basics", or simply just removing the "plugins" block in the "configuration" section of the plugin? If so, I just tried that, and it had no effect. Is your statement about "The main branch can be ..." addressing my question about setting up a local environment so I can debug it myself? If so, I would need more than that. I would need to be able to step through the code in Eclipse, while running the generation as specified in my build. |
When I need to debug some configuration, I add it to the tests projectd and then run debug but I do it in IntelliJ, not tested in Eclipse. Since you are using eclipse, could you send me your last tests output of mvn with Thanks |
I just learned about the "mvnDebug" app, and inspecting it, I see how easy it is to set up mvn so I can debug this, so I might do this on Monday. I assumed it would be more complicated than this. |
I've re-read your answer and looked at the effective pom, and could you please try again with removing of the following lines in the plugin configuration : <args>
<arg>-Xsetters</arg>
<arg>-Xsetters-mode=direct</arg>
</args>
<plugins /> Thanks |
I assume you mean just the "args" block, and not the ending "plugins" marker. I tried that. No change. |
No I meant both blocks |
Interesting. That got a result. When I had an empty plugins block:
it still gets the error. When I commented out the plugins block entirely, it completes the generation and goes onto compiling the code:
I have no idea whether those plugins are really required. I see many of our developers include those blocks, but I've never bothered to analyze the result and difference. |
I was pretty sure that'd help your case by removing plugins section (and corresponding args) in the maven-plugin configuration because the NPE is related with some resolved artefact related to the project itself with I've tried to copy on a test project almost everything I could from your effective pom section but I didn't get it to fail as you did. One good advice I could give is try to split this code generation in a simple module, with plugins activated but with no extra and useless dependencies. You can find the If you manage to debug your current config, please let me know what failed. We could for sure add extra failsafe to remove |
I would not be at all surprised if one of those "proprietary" dependencies, which we have little control over in our "platform" team has some WTF in it that none of us expected. I hope hitting the breakpoint at that line that throws the exception will lead to that discovery. I have that in my tasks for tomorrow. I'll relate everything that I find. |
Ok, I cloned jaxb-tools, checking out master, and started running some tests with the debugger. I noticed that some of the methods weren't "lining up", so I instead checked out the 4.0.8 tag, and that worked a little better. It will be a little hard for me to tell when what I'm seeing is a true anomaly. I'll describe what I do and see. I changed the pom.xml to restore everything we had in the configuration block before. I first looked at what I get at "org.jvnet.jaxb.maven.RawXJCMojo.resolveXJCPluginArtifacts (RawXJCMojo.java:400)", which is this:
I first note that the "plugins" list has two entries, with artifactIds "jaxb2-basics" and "jaxb-plugins". The xjcPluginFiles list is length 434, and every entry is null. The xjcPluginArtifacts list is also 434 entries, likely with no null entries. The 0th entry has artifactId "jaxb2-basics". However, the "file" property is null. The actual type of all of the entries of this list is DefaultArtifact. I see there are three subclasses of Artifact, but I also see that there are three subclasses of DefaultArtifact. All of these actual types are just DefaultArtifact, not any of the subclasses of DefaultArtifact, like PluginArtifact or ProjectArtifact. I would step into "ArtifactUtils.getFiles()", but I think it's pointless with what I see here, as that just gets the "file" property from each one of these. It's reasonable to consider setting a breakpoint on DefaultArtifact.setFile() , but of course that gets hit hundreds of times. So, I made it a conditional breakpoint for |
Many thanks for the detailed explanation.
I'm a bit surprised about the two entries in "plugins" : you should only have the jaxb-plugins in it. Could you send me more details about the Thanks |
[0] Dependency (id=1761) Dependency |
Do you have any |
The only place it is referenced is in that plugins block in the configuration for the jaxb-maven-plugin. Frankly, every time I've ever built something using jaxb-maven-plugin, I never used these plugins. I see this being done in numerous poms maintained by other developers here. I assumed they had a good reason to do it, but I've never examined them. |
OK but you said earlier that
So at some point, you should have both plugins in The |
I'm not certain what you're suggesting. Are you saying that the jaxb2-basics plugin is pointless and could be removed? Note that these configurations have been like this for a long time. We recently did a big upgrade from Java 11, SpringBoot 2, and Spring 5 to Java 17, SpringBoot 3, and Spring 6. This plugin was also upgraded. In fact, I believe we were even using a different plugin, one with a similar name.
|
In order to move to SB3, you needed to go with the latest version (main branch, 4.x version) of jaxb-maven-plugin, and more generaly jaxb-tools. Starting with v2 (based on javaee8, jaxb2.3) of the maven-plugin, we did some reorganisation about others highsource's repositories and merged them here in order to have a complete set of tools, with same groupId ( Users of legacies artifacts (0.x, 1.x) moving to the new ones (any versions) or users moving from javax to jakarta (below 2.x to 3.x and upper) are really encouraged to read the migration guide pointed above. Back to your issue : I didnt manage to add the old artifact jaxb2-basics:0.11.1 in my test project without adding back jaxb-api / jaxb-runtime 2.x as project's / plugin's dependency. Maybe your issue occurs because of some transformer process (like javax to jakarta eclipse transformer thing) ? |
Remember, we were still getting this error when I had an empty plugins block. It was only removing the entire plugins block that made the error go away. Actually, I'm going to test that again, and this time in the debugger. We are using the transformer, but that doesn't happen until compile stage. |
I ran another test with this as the configuration block:
In "org.jvnet.jaxb.maven.RawXJCMojo.resolveXJCPluginArtifacts()", the plugins list is a zero-length list. The "xjcPluginFiles" list is length 426 (434 before), but still has all null entries. The plugins issue seems to be a red herring. In the xjcPluginArtifacts list, all of the "file" properties are null, so something is happening in "ArtifactUtils.resolveTransitively()" that causes this. Oh, but our plugins list is empty. Why do we have a list of xjcPluginFiles with 426 entries (all null) if we're not using any plugins? |
That is somehow strange that all files are null entries. |
I tried stepping into more code, which gets into maven-core and maven-compat. It appears these 426 artifacts somehow correspond to all of the dependencies in the pom. It's a little hard to tell what it is doing, but that's the impression I got. I have no idea whether it makes sense for those to be considered the "xjcArtifacts". |
Could you tell me which version of mvn you're using please ? |
Since you managed to run debug mode, could you see if the artifactresolver enter in this condition : |
We're using Maven 3.9.6. The line number for that block of code is slightly different in 3.9.6 (line 489). When I hit that check, metadataResolutionExceptions and CircularDependencyExceptions were both null, but versionRangeViolations had 35 entries. The first one of 35 was this:
I don't know what this means. |
From what I understand in your stacktrace, you got exception in version range selection in some of your dependencies like this one In your project, I can see this
So you're expecting to have The |
This is a familiar problem to us. My "platform" team maintains the BOM and some common libraries like rest-api-client and idp-spring-boot-autoconfigure, and the parent pom. We tell developers that they cannot override versions of the artifacts we provide, but it happens all the time in artifacts like that "idp-services-common" thing, which we do not maintain. However, these mistakes usually manifest in more obvious symptoms, like MethodNotFound, ClassDefNotFound, et cetera. It's really odd for that to produce a symptom like this. I wonder if there's some way we can get these "metadataResolutionExceptions" to be more visible? Is this something I should take to the Maven list? |
Could you first confirm that fixing this will solve your problem ? I'll check if we get this information in the xjcPlugin resolution process in order to fail with a-non-odd exception (like here : NPE) |
In fact yes, it's available, so we could enforce there's no error in order to carry on the generation process. |
@davidmichaelkarr : could you provide me the I'm still trying to reproduce the issue Thanks :) |
Ok, well, some of those are just the "top-level" pom that leads to that dependency spec. I'll map out the path along the way. Note that several of these blocks actually reference variables for the version strings. I'm hardcoding those values to avoid that additional level of indirection here. In "com.att.idp:UnifiedAccountMs:jar:0.0.1-SNAPSHOT", the top-level pom.xml for the service I'm debugging, it just has this:
It has no version because we wire versions in the parent poms. This pom also has this parent declaration:
The "sdk-java-parent:2.9.0" artifact then references our BOM in dependencyManagement:
Then in "idp-bom:2.9.0" we have this in dependencyManagement:
In "com.att.idp:idp-services-commons:jar:1.4, it doesn't have an explicit reference to that dependency, but it has this:
In "sdk-java-library-parent:2.8.0" it has this BOM dependency:
And "idp-bom:2.8.0" has this:
Now in "rest-api-client:2.8.0", it has an unversioned spec for it:
Along with this:
That is the identical subpath to the reference from idp-services-commons:1.4. |
Found solution for a similar issue. We have two gitlab pipelines. One is air-gabbed so we have to manually transfer files from one to the other. It would pass in the first and fail in the second. I was getting the same error "[ERROR] Failed to execute goal org.jvnet.jaxb:jaxb-maven-plugin:4.0.8:generate (generate) on project topproject: Execution generate of goal org.jvnet.jaxb:jaxb-maven-plugin:4.0.8:generate failed: Cannot invoke "java.io.File.toURI()" because "file" is null " I tried enabling verbose and debug but it didn't help me figure it out. If I removed the jaxb-plugins extension and not generate the equals/hashcode then it succeeded. I added the jaxb-plugins as a explicit not just a and then it showed the other dependencies that were missing. Once I added that the file is null went away. |
We've been using "jaxb-maven-plugin" for a long time to generate JAXB classes from wsdls and xsds. There are occasional unusual issues we have to deal with, but we've always gotten it to work. We maintain a large number of SpringBoot services, many of which use this to generate JAXB classes from many different schemas.
Today I started looking at one build that is failing with an odd error:
This pom.xml has several "execution" blocks, but I've tried commenting all but one, and other variations, but all of those experiments fail with the same error (with a different execution name).
I've verified that the "sourceDirectory" refers to an existing directory that has a wsdl in it, with several xsd files. Each execution block looks something like this:
What are possible causes of this?
The text was updated successfully, but these errors were encountered: