You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@excalibur.apache.org by Vadim Gritsenko <va...@reverycodes.com> on 2004/09/28 02:16:01 UTC

Bug in SourceUtil.copy()

Hi all,

Currently SourceUtil.copy(Source, Source) does not:

  * Close InputStream when its done with it
  * Cancel OutputStream when failed to copy

Attached patch fixes these issues. Can somebody apply it?


PS I found no ant script, and maven fails - is it normal?

Thanks,
Vadim


Building Excalibur, Re: Bug in SourceUtil.copy()

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leif Mortenson wrote:

> Vadim Gritsenko wrote:
> 
>> Leif Mortenson wrote:
>>
>>> To build the whole tree, cd into the Excalibur root and run:
>>> maven multiproject:install
>>
>>
>> I was soo naive. I was trying simply "maven" from excalibur, and from 
>> excalibur/components/sourceresolve directories.
>>
>> Now, it fails with:
>>
>>   BUILD FAILED
>>   File...... file:/.../.maven/plugins/maven-multiproject-plugin-1.1/
>>   Element... maven:reactor
>>   Line...... 174
>>   Column.... 9
>>   The build cannot continue because of the following unsatisfied 
>> dependencies:
>>
>>   mailapi-1.3.1.jar (no download url specified)
>>   jms-1.1.jar (no download url specified)
> 
> 
> You will need to download those from the Sun site and place them into 
> the appropriate
> locations in your local maven repository.   Due to licensing issues.  We 
> can not provide
> them ourselves, or even point directly to jar download locations.  :-/

Ok, next step, now it fails with:

..
+----------------------------------------
| Executing multiproject:install-callback Excalibur Component Manager
| Memory: 61M/83M
+----------------------------------------


multiproject:install-callback:
     [echo] Running jar:install for Excalibur Component Manager
java:prepare-filesystem:

java:compile:
     [echo] Compiling to 
C:\Work\Apache\excalibur\.\deprecated\component/target/classes
     [javac] Compiling 30 source files to 
C:\Work\Apache\excalibur\deprecated\component\target\classes
C:\Work\Apache\excalibur\deprecated\component\src\java\org\apache\avalon\excalibur\component\AbstractDualLogEnabledInstr
umentable.java:21: package org.apache.excalibur.instrument does not exist
import org.apache.excalibur.instrument.Instrument;
                                        ^
C:\Work\Apache\excalibur\deprecated\component\src\java\org\apache\avalon\excalibur\component\AbstractDualLogEnabledInstr
umentable.java:22: package org.apache.excalibur.instrument does not exist
import org.apache.excalibur.instrument.Instrumentable;
                                        ^
...
100 errors

BUILD FAILED
File...... file:/C:/Documents and 
Settings/gritsenkov/.maven/plugins/maven-multiproject-plugin-1.1/
Element... maven:reactor
Line...... 174
Column.... 9
Unable to obtain goal [multiproject:install-callback] -- 
file:/C:/Documents and Settings/gritsenkov/.maven/plugins/maven
-java-plugin-1.3/:34:48: <ant:javac> Compile failed; see the compiler 
error output for details.
Total time: 1 minutes 53 seconds
Finished at: Tue Sep 28 13:39:38 EDT 2004


Thanks,
Vadim


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/


Re: Bug in SourceUtil.copy()

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leif Mortenson wrote:

> Vadim Gritsenko wrote:
> 
>> Leif Mortenson wrote:
>>
>>>    I committed a modified patch to SVN as well as went through and 
>>> added javadocs to
>>> the relevant interfaces making it more obvious that these streams 
>>> need to be closed by the
>>> calling code.  Could you take a look at the changes and post back if 
>>> you see any problems.
>>
>>
>> There are couple of issues... You are loosing original IOException in 
>> lines 520, 533, 539:
>>   520: modDestination.cancel( out );
>>   533: out.close();
>>   539: in.close();
>> If an IOException has been thrown already, any new IOException which 
>> can happen in these lines will cause original IOException to get lost.
>>
>> Worst case scenario, you are loosing 3 IOExceptions and showing only 
>> the very last, fourth one. My gut feeling tells me the very first one 
>> usually way more informative than the fourth one.
>>
>> I guess, ideally, you would preserve original exception in all glory, 
>> and add messages from all of the following exceptions if you don't 
>> want to ignore them:
>>   message += "and on top of that, you've got " + e;
> 
> 
> Good point, I was more concerned with being careful that all streams are 
> always closed
> appropriately.   It now keeps track of the first exception thrown and 
> wraps that in a
> SourceException.  Thanks for pointing that out.

Thanks, that's better :-)


PS What's the current release of excalibur-sourceresolve? And when's 
next one? http://www.apache.org/dist/excalibur/ is empty. There is stuff 
under http://www.apache.org/dist/avalon/ though.

Vadim


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/


Re: Bug in SourceUtil.copy()

Posted by Leif Mortenson <le...@tanukisoftware.com>.
Vadim Gritsenko wrote:

> Leif Mortenson wrote:
>
>>    I committed a modified patch to SVN as well as went through and 
>> added javadocs to
>> the relevant interfaces making it more obvious that these streams 
>> need to be closed by the
>> calling code.  Could you take a look at the changes and post back if 
>> you see any problems.
>
>
> There are couple of issues... You are loosing original IOException in 
> lines 520, 533, 539:
>   520: modDestination.cancel( out );
>   533: out.close();
>   539: in.close();
> If an IOException has been thrown already, any new IOException which 
> can happen in these lines will cause original IOException to get lost.
>
> Worst case scenario, you are loosing 3 IOExceptions and showing only 
> the very last, fourth one. My gut feeling tells me the very first one 
> usually way more informative than the fourth one.
>
> I guess, ideally, you would preserve original exception in all glory, 
> and add messages from all of the following exceptions if you don't 
> want to ignore them:
>   message += "and on top of that, you've got " + e;

Good point, I was more concerned with being careful that all streams are 
always closed
appropriately.   It now keeps track of the first exception thrown and 
wraps that in a
SourceException.  Thanks for pointing that out.

>> fine on my system.  What version of Maven are you using? and what is 
>> the failure you are
>> seeing?
>>    To build the whole tree, cd into the Excalibur root and run:
>> maven multiproject:install
>
>    As for the build, we are using Maven now rather than Ant.   The 
> Maven build is working
>
> I was soo naive. I was trying simply "maven" from excalibur, and from 
> excalibur/components/sourceresolve directories.
>
> Now, it fails with:
>
>   BUILD FAILED
>   File...... file:/.../.maven/plugins/maven-multiproject-plugin-1.1/
>   Element... maven:reactor
>   Line...... 174
>   Column.... 9
>   The build cannot continue because of the following unsatisfied 
> dependencies:
>
>   mailapi-1.3.1.jar (no download url specified)
>   jms-1.1.jar (no download url specified)

You will need to download those from the Sun site and place them into 
the appropriate
locations in your local maven repository.   Due to licensing issues.  We 
can not provide
them ourselves, or even point directly to jar download locations.  :-/

Cheers,
Leif

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/


Re: Bug in SourceUtil.copy()

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leif Mortenson wrote:

> Vadim,
>    Thanks for your patch.  Looking over it, it looks like the output 
> stream would still not be
> closed in the case where there were not any errors.

Yup, forgot one line :)


>    I committed a modified patch to SVN as well as went through and added 
> javadocs to
> the relevant interfaces making it more obvious that these streams need 
> to be closed by the
> calling code.  Could you take a look at the changes and post back if you 
> see any problems.

There are couple of issues... You are loosing original IOException in 
lines 520, 533, 539:
   520: modDestination.cancel( out );
   533: out.close();
   539: in.close();
If an IOException has been thrown already, any new IOException which can 
happen in these lines will cause original IOException to get lost.

Worst case scenario, you are loosing 3 IOExceptions and showing only the 
very last, fourth one. My gut feeling tells me the very first one 
usually way more informative than the fourth one.

I guess, ideally, you would preserve original exception in all glory, 
and add messages from all of the following exceptions if you don't want 
to ignore them:
   message += "and on top of that, you've got " + e;


>    As for the build, we are using Maven now rather than Ant.   The Maven 
> build is working
> fine on my system.  What version of Maven are you using? and what is the 
> failure you are
> seeing?
>    To build the whole tree, cd into the Excalibur root and run:
> maven multiproject:install

I was soo naive. I was trying simply "maven" from excalibur, and from 
excalibur/components/sourceresolve directories.

Now, it fails with:

   BUILD FAILED
   File...... file:/.../.maven/plugins/maven-multiproject-plugin-1.1/
   Element... maven:reactor
   Line...... 174
   Column.... 9
   The build cannot continue because of the following unsatisfied 
dependencies:

   mailapi-1.3.1.jar (no download url specified)
   jms-1.1.jar (no download url specified)

It's maven-1.0-rc1.

Thanks,
Vadim


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/


Re: Bug in SourceUtil.copy()

Posted by Leif Mortenson <le...@tanukisoftware.com>.
Vadim,
    Thanks for your patch.  Looking over it, it looks like the output 
stream would still not be
closed in the case where there were not any errors.
    I committed a modified patch to SVN as well as went through and 
added javadocs to
the relevant interfaces making it more obvious that these streams need 
to be closed by the
calling code.  Could you take a look at the changes and post back if you 
see any problems.

    As for the build, we are using Maven now rather than Ant.   The 
Maven build is working
fine on my system.  What version of Maven are you using? and what is the 
failure you are
seeing?
    To build the whole tree, cd into the Excalibur root and run:
maven multiproject:install

Cheers,
Leif

Vadim Gritsenko wrote:

> Hi all,
>
> Currently SourceUtil.copy(Source, Source) does not:
>
>  * Close InputStream when its done with it
>  * Cancel OutputStream when failed to copy
>
> Attached patch fixes these issues. Can somebody apply it?
>
>
> PS I found no ant script, and maven fails - is it normal?
>
> Thanks,
> Vadim
>
>------------------------------------------------------------------------
>
>Index: components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java
>===================================================================
>--- components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java	(revision 47353)
>+++ components/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java	(working copy)
>@@ -1,29 +1,34 @@
>-/* 
>+/*
>  * Copyright 2002-2004 The Apache Software Foundation
>  * Licensed  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 
>- * 
>+ * 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.excalibur.source;
> 
>-import java.io.*;
>+import java.io.ByteArrayOutputStream;
>+import java.io.File;
>+import java.io.IOException;
>+import java.io.InputStream;
>+import java.io.OutputStream;
>+import java.io.OutputStreamWriter;
>+import java.io.UnsupportedEncodingException;
> import java.util.BitSet;
> import java.util.Iterator;
> 
> import org.apache.avalon.framework.parameters.Parameters;
> 
> /**
>- *
>  * Utility class for source resolving.
>  *
>  * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
>@@ -493,16 +498,36 @@
>                                           "' is not writeable");
>             }
> 
>+            InputStream in = null;
>+            OutputStream out = null;
>             try {
>-                OutputStream out = ((ModifiableSource) destination).getOutputStream();
>-                InputStream in = source.getInputStream();
>+                out = ((ModifiableSource) destination).getOutputStream();
>+                in = source.getInputStream();
> 
>                 copy(in, out);
>             } catch (IOException ioe) {
>+                if (out != null && ((ModifiableSource) destination).canCancel(out)) {
>+                    try {
>+                        ((ModifiableSource) destination).cancel(out);
>+                    } catch (IOException e) {
>+                        throw new SourceException("Could not copy source '" +
>+                                                  source.getURI() + "' to '" +
>+                                                  destination.getURI() + "' (" +
>+                                                  ioe.getMessage() +
>+                                                  ") and can't cancel output: " +
>+                                                  e.getMessage(), ioe);
>+                    }
>+                }
>+
>                 throw new SourceException("Could not copy source '"+
>                                           source.getURI()+"' to '"+
>                                           destination.getURI()+"' :"+
>                                           ioe.getMessage(), ioe);
>+            } finally {
>+                try {
>+                    if (in != null)
>+                        in.close();
>+                } catch (IOException ignored) { }
>             }
>         }
>     }
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
>For additional commands, e-mail: dev-help@excalibur.apache.org
>Apache Excalibur Project -- URL: http://excalibur.apache.org/
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@excalibur.apache.org
For additional commands, e-mail: dev-help@excalibur.apache.org
Apache Excalibur Project -- URL: http://excalibur.apache.org/