You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2021/02/14 19:18:41 UTC

[GitHub] [cxf] reta opened a new pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

reta opened a new pull request #745:
URL: https://github.com/apache/cxf/pull/745


   Multiple input stream leaks where `URIResolver` is used. Marked `URIResolver`  as `AutoCloseable` and refactored its usage to `try-with-resources` in most places.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r576169125



##########
File path: tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
##########
@@ -1305,9 +1305,10 @@ private static String mapSchemaLocation(String target, String base, OASISCatalog
 
 
         try {
-            URIResolver resolver = new URIResolver(base, target);
-            if (resolver.isResolved()) {
-                target = resolver.getURI().toString();
+            try (URIResolver resolver = new URIResolver(base, target)) {

Review comment:
       Nope, outer is enough, thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] amarkevich commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
amarkevich commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r575965816



##########
File path: tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
##########
@@ -118,8 +118,9 @@ private void addBinding(String bindingFile) throws XMLStreamException {
 
         Element root = null;
         try {
-            URIResolver resolver = new URIResolver(bindingFile);
-            root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
+            try (URIResolver resolver = new URIResolver(bindingFile)) {

Review comment:
       there are same changes in another places...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] coheigea commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
coheigea commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r576610259



##########
File path: rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
##########
@@ -729,10 +729,10 @@ static void setupClasspath(StringBuilder classPath, ClassLoader classLoader)
 
     private URL composeUrl(String s) {
         try {
-            URIResolver resolver = new URIResolver(null, s, getClass());
-
-            if (resolver.isResolved()) {
-                return resolver.getURI().toURL();
+            try (URIResolver resolver = new URIResolver(null, s, getClass())) {

Review comment:
       Can we remove the nested try statements here as well?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r576804816



##########
File path: rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
##########
@@ -729,10 +729,10 @@ static void setupClasspath(StringBuilder classPath, ClassLoader classLoader)
 
     private URL composeUrl(String s) {
         try {
-            URIResolver resolver = new URIResolver(null, s, getClass());
-
-            if (resolver.isResolved()) {
-                return resolver.getURI().toURL();
+            try (URIResolver resolver = new URIResolver(null, s, getClass())) {

Review comment:
       This one is a bit tricky since the `ServiceConstructionException` has to be thrown if URI is not resolved and not throwing any exceptions. I refactored it, please let me know what do you think.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r576168307



##########
File path: core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
##########
@@ -100,10 +100,10 @@ public String getResolvedEntity(String publicId, String systemId) {
                     String s = super.getResolvedEntity(publicId, systemId);
                     if (s != null && s.startsWith("classpath:")) {
                         try {
-                            URIResolver r = new URIResolver(s);
-                            if (r.isResolved()) {
-                                r.getInputStream().close();
-                                return r.getURL().toExternalForm();
+                            try (URIResolver r = new URIResolver(s)) {

Review comment:
       No, not really in this case, simplified, thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r575918652



##########
File path: tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
##########
@@ -118,8 +118,9 @@ private void addBinding(String bindingFile) throws XMLStreamException {
 
         Element root = null;
         try {
-            URIResolver resolver = new URIResolver(bindingFile);
-            root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
+            try (URIResolver resolver = new URIResolver(bindingFile)) {

Review comment:
       👍 , fixed, thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r575918652



##########
File path: tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
##########
@@ -118,8 +118,9 @@ private void addBinding(String bindingFile) throws XMLStreamException {
 
         Element root = null;
         try {
-            URIResolver resolver = new URIResolver(bindingFile);
-            root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
+            try (URIResolver resolver = new URIResolver(bindingFile)) {

Review comment:
       :+1, fixed, thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r576173789



##########
File path: tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
##########
@@ -118,8 +118,9 @@ private void addBinding(String bindingFile) throws XMLStreamException {
 
         Element root = null;
         try {
-            URIResolver resolver = new URIResolver(bindingFile);
-            root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
+            try (URIResolver resolver = new URIResolver(bindingFile)) {

Review comment:
       Tried to address all of them, there are some places where I had to keep nested`try` structures since the exiting behavior (throw or return) would change.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta merged pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta merged pull request #745:
URL: https://github.com/apache/cxf/pull/745


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] reta commented on pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
reta commented on pull request #745:
URL: https://github.com/apache/cxf/pull/745#issuecomment-778826992


   @coheigea would you mind to take a look please, should not take long, thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] coheigea commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
coheigea commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r575983865



##########
File path: tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
##########
@@ -1305,9 +1305,10 @@ private static String mapSchemaLocation(String target, String base, OASISCatalog
 
 
         try {
-            URIResolver resolver = new URIResolver(base, target);
-            if (resolver.isResolved()) {
-                target = resolver.getURI().toString();
+            try (URIResolver resolver = new URIResolver(base, target)) {

Review comment:
       Do we really need to have a nested try statement here?

##########
File path: core/src/main/java/org/apache/cxf/catalog/OASISCatalogManager.java
##########
@@ -100,10 +100,10 @@ public String getResolvedEntity(String publicId, String systemId) {
                     String s = super.getResolvedEntity(publicId, systemId);
                     if (s != null && s.startsWith("classpath:")) {
                         try {
-                            URIResolver r = new URIResolver(s);
-                            if (r.isResolved()) {
-                                r.getInputStream().close();
-                                return r.getURL().toExternalForm();
+                            try (URIResolver r = new URIResolver(s)) {

Review comment:
       Do we really need to have a nested try statement here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cxf] amarkevich commented on a change in pull request #745: CXF-8422: Unclosed input streams after using org.apache.cxf.tools.wsdlto.WSDLToJava

Posted by GitBox <gi...@apache.org>.
amarkevich commented on a change in pull request #745:
URL: https://github.com/apache/cxf/pull/745#discussion_r575863711



##########
File path: tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxb/CustomizationParser.java
##########
@@ -118,8 +118,9 @@ private void addBinding(String bindingFile) throws XMLStreamException {
 
         Element root = null;
         try {
-            URIResolver resolver = new URIResolver(bindingFile);
-            root = StaxUtils.read(resolver.getInputStream()).getDocumentElement();
+            try (URIResolver resolver = new URIResolver(bindingFile)) {

Review comment:
       redundant inner try




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org