-
Notifications
You must be signed in to change notification settings - Fork 399
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
ClassLoader Issues with ObjectNode #30
Comments
Oh f*... I didn't foresee this problem :/ OK, I'll explain why I did it:
So, this is clearly a bug, and I have never seen it here (I am using IDEA, but that probably does not explain things). The solution, of course, is to remove that Would you have the possibility to alter your setup to use a fork of Sorry for that :/ |
OK, the commit is now in |
Sorry, git mishap... Can you pull again? I forgot to include the modification to |
Issue #30 shows that this can lead to a problem I would never had foreseen until I saw it with my own eyes: the fact that the new ObjectNode implementation adds an .asMap() method can cause problems. As a result, re-introduce a JacksonUtils class with a sole asMap() method which does the same thing. Jackson is to blame here: ContainerNode<T> returns subclasses of itself in only two methods. Two. But that is enough so that I must override ObjectNode and ArrayNode this way, with this kind of problems lurking behind :/ Link: #30 Signed-off-by: Francis Galiegue <[email protected]>
Yet another mishap... Sorry about this :/ |
I pulled and tested on master and no longer encounter the error. I can stay on master, I had only downgraded to 1.4 to troubleshoot. While there is no longer a conflict of method signatures, it would seem to me that there is still a latent issue with classloading since there are two copies of this class. While I don't see any problematic behavior now, I wouldn't be surprised if this manifests itself later. I have previously run into ClassNotFoundExceptions if I have a duplicate class on the classpath. Is there a reason you can't just extend ObjectNode and override to add your desired functionality? |
Apart from I figured out that just replacing So, you are right, I need to extend it. I just need to figure out how I'll combine the whole so that In the meanwhile, the current solution is easily backported to 1.4.x, do you have any interest in my doing so? It is a critical enough bug that I spawn a new 1.4.x with just that commit in any case. |
I have written my schemas based around the draft version 4. I know this is not finalized yet, but I had an easier time accomplishing things with it. My schemas are working with both 1.4.X and 1.5. I am open to using whichever branch you feel is the best bet for an enterprise environment. |
OK well, in an enterprise environment, I guess the best bet is the currently declared stable version, right? In this case, You have just made me wonder something: you say you are using draft v4, how do you declare using draft v4 using the current code? Is that using |
Issue #30 shows that this can lead to a problem I would never had foreseen until I saw it with my own eyes: the fact that the new ObjectNode implementation adds an .asMap() method can cause problems. As a result, re-introduce a JacksonUtils class with a sole asMap() method which does the same thing. Jackson is to blame here: ContainerNode<T> returns subclasses of itself in only two methods. Two. But that is enough so that I must override ObjectNode and ArrayNode this way, with this kind of problems lurking behind :/ Link: #30 Signed-off-by: Francis Galiegue <[email protected]>
* Do not add .asMap() method to custom (package-equal) ObjectNode implementation: if another implementation is loaded before ours, this will lead to class loader errors (issue #30) Francis Galiegue (1): Remove .asMap() method from custom ObjectNode implementations Signed-off-by: Francis Galiegue <[email protected]>
OK, I have completed maven artifact publication for 1.4.2, which fixes this bug in particular (although the underlying problem is still there as you have clearly demonstrated). In short, if you are using 1.4.2:
Unfortunately, I cannot guarantee the delay for availability of maven artifacts... I'd appreciate if you could update this bug when you see 1.4.2 available. |
And make our CustomJsonNodeFactory return these overrides instead of the plain ObjectNode and ArrayNode. See issue #30. Signed-off-by: Francis Galiegue <[email protected]>
OK, 1.4.2 is here with a quick fix and a more complete fix is in Do you want me to backport the more complete fix to 1.4.x? |
Yes, if you could port the complete fix to 1.4.x it would be very helpful. I believe you asked for my usage of schemas in an earlier post. Here is what I have done so far:
|
OK, I will backport the fix soon. Just one note about your schemas; you have a lot of: {
"type": "string":
"enum": [ "some", "string", "values", "here" ]
} The Also, you use, in one place: {
"allOf": [
{ "$ref": "whatever" }
]
} No need for I'll let you know when I have pushed 1.4.3. |
And make our CustomJsonNodeFactory return these overrides instead of the plain ObjectNode and ArrayNode. Update Javadoc as well. See issue #30. Signed-off-by: Francis Galiegue <[email protected]>
1.4.3 has been released. When you have the opportunity, can you test it and report? |
I pulled the 1.4.X branch -- the pom says 1.4.4 -- and it passes my (limited) test case. Thanks a lot. By the way, is there a reason you release versions with a version of X.Y.Z-SNAPSHOT instead of X.Y.Z-RELEASE? It would seem appropriate to make the distinction that it was a release version. I bring this up because our Nexus repository policy is to only allow third-party libs that are a release version. For now I am manually changing this in your pom but it seems like you would want formal releases to be labeled as such. Thanks again, |
Wait wait wait...
and
There is none, apart from my scarce knowledge of maven and, maybe (I cannot tell), the fact that I use SonaType's release plugin. To be brutally honest, I know it works, but I don't know why (or how) it works. All I know is that this plugin modifies pom.xml twice, in two different commits:
But as I do NOT want to pollute my repository with commits NOT generated by me (I positively hate this plugin's commit messages, especially since it leaves no opportunity to edit them, and I hate that a plugin creates a commit for me), I just let these commits go to a "throw out" branch and publish to github a rebased version of changes with the shortlog etc. In effect, it means that while code-wise, what is published via Sonatype is equivalent to what is on the matching tag on GitHub, what is on GitHub is what I want to see in the tree, "freed of" Sonatype's commit garbage. (another reason why I do that is that Sonatype's release plugin insists on cloning the entire repository for a compile using whatever is behing XPATH OK, all of this rant to ask: how do you integrate the library to your project exactly? I think I can learn a lot here. So, yes, I am reopening this issue, although this is not related to the original bug anymore -- this time, it is I asking for your input ;) |
In my code I am using ProcessingReport report = schema.validate(jsonNode); There is no compilation issue and when I run the test from the same project it is not giving any exception. But when I execute the same by adding dependency of my current project to another project and then running the test from that project, I am getting the following error : java.lang.NoSuchMethodError: com.github.fge.jsonschema.main.JsonSchema.validate(Lcom/fasterxml/jackson/databind/JsonNode;)Lcom/github/fge/jsonschema/core/report/ProcessingReport; |
I see that you have overriden com.fasterxml.jackson.databind.node.ObjectNode in your jar. This is causing class loading issues for when trying to invoke your code. When I have both json-schema-validator and jackson-databind on my classpath in eclipse, it is loading the jackson-databind's version of ObjectNode instead of yours. This is causing the following error:
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.ObjectNode.asMap()Ljava/util/Map; at org.eel.kitchen.jsonschema.validator.ObjectValidator.<init>(ObjectValidator.java:68) at org.eel.kitchen.jsonschema.validator.InstanceValidator.validate(InstanceValidator.java:89) at org.eel.kitchen.jsonschema.main.JsonSchema.validate(JsonSchema.java:71) at com.dibs.json_validator.AppTest.testJSON(AppTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Is there some standard workaround or solution for this? I would prefer not to mess with my classloader. I am using the latest version of the 1.4 branch.
The text was updated successfully, but these errors were encountered: