This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 207646 - IOE "read wrong amount" from NbModuleSuite$S.rewrite
Summary: IOE "read wrong amount" from NbModuleSuite$S.rewrite
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: NB JUnit (show other bugs)
Version: 7.1
Hardware: All All
: P2 normal with 1 vote (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
: 211297 (view as bug list)
Depends on: 212197
Blocks:
  Show dependency tree
 
Reported: 2012-01-23 18:48 UTC by alexandru.stan
Modified: 2012-05-10 17:49 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Contains the sources and the results from running the tests (24.48 KB, application/x-zip-compressed)
2012-01-23 18:48 UTC, alexandru.stan
Details
the application to reproduce the error (21.79 KB, application/x-zip-compressed)
2012-01-28 17:27 UTC, alexandru.stan
Details
surefire report for the wrapper module error (2.79 KB, application/x-zip-compressed)
2012-01-28 17:36 UTC, alexandru.stan
Details
Test case for endless loop (11.79 KB, application/zip)
2012-04-18 12:16 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alexandru.stan 2012-01-23 18:48:07 UTC
Created attachment 115170 [details]
Contains the sources and the results from running the tests

I was trying to create a functional test to a platform application and I encountered a problem because I had also external dependencies in some modules and when I run the test those modules will not load. 
I followed the tutorial from: http://netbeans.dzone.com/nb-mvn-functional-tests
I also attached my sources and the result from surefire.

Steps to reproduce:
1. Create a new Maven-based NetBeans Platform application via the related template in the IDE.
2. Add a new class "DoStuff" in the sample module and resolve the dependecies problems
3. Create new folders in the app module: "src/test/java"
4. Add a new class "FuncTest" and resolve the dependecies problems
5. Run test (right click on the app module and test to run integration-test goal)

Result: the test is running succesfully (surefire-reports_success directory)

6. Add an external library like lib-common (http://mvnrepository.com/artifact/nl.cloudfarming.client/lib-common) to the sample module
7. Rebuid and run the test again

Expected result: The test should run ok

Actual result: The test is running but a lot of java.io.FileNotFoundException are thrown in the console as you can see in the console.txt file from surefire-reports_errors directory.

My guess is that it is trying to load the libraries from the classpath and not from the maven repository.
Comment 1 Jaroslav Tulach 2012-01-24 10:24:39 UTC
NBJUnit in Maven report.
Comment 2 Jesse Glick 2012-01-25 18:50:16 UTC
The problem is in that particular artifact's manifest:

Class-Path: ext/commons-collections/commons-collections-3.2.1.jar ....

should not be there. MNBMODULE-133 already fixed this in the 3.6 version of the plugin, but presumably this module was built using an earlier version of the plugin. (It is hard to say for sure since the POM [2] is missing a version for the plugin, which is poor practice [3].)

[1] https://jira.codehaus.org/browse/MNBMODULE-133
[2] https://hg.java.net/hg/nb-library-wrappers~core/file/fba56fd88ddd/lib-commons/pom.xml
[3] https://cwiki.apache.org/MAVEN/maven-3x-compatibility-notes.html#Maven3.xCompatibilityNotes-AutomaticPluginVersionResolution
Comment 3 alexandru.stan 2012-01-28 17:27:37 UTC
Created attachment 115344 [details]
the application to reproduce the error
Comment 4 alexandru.stan 2012-01-28 17:29:50 UTC
Thanks Jesse.
You were right that library was build with an old version and had problems with the classpath.

I gave up using that. I need two libraries from the commons the lang and the collection.

I created a wrapper module that will add these libraries to the application.
This module is a dependency to the sample.

When I run the test I'm getting:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.484 sec <<< FAILURE!
org.netbeans.junit.NbModuleSuite$S@765291(org.netbeans.junit.NbModuleSuite$S)  Time elapsed: 0 sec  <<< ERROR!
java.io.IOException: read wrong amount
	at org.netbeans.junit.NbModuleSuite$S.rewrite(NbModuleSuite.java:1146)
	at org.netbeans.junit.NbModuleSuite$S.turnClassPathModules(NbModuleSuite.java:1080)
	at org.netbeans.junit.NbModuleSuite$S.runInRuntimeContainer(NbModuleSuite.java:855)
	at org.netbeans.junit.NbModuleSuite$S.access$100(NbModuleSuite.java:660)
	at org.netbeans.junit.NbModuleSuite$S$1.protect(NbModuleSuite.java:679)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	..............

I added the project and the surefire report to the attachements
Comment 5 alexandru.stan 2012-01-28 17:36:58 UTC
Created attachment 115345 [details]
surefire report for the wrapper module error
Comment 6 Jesse Glick 2012-01-31 17:54:28 UTC
This looks like a completely unrelated bug that really should have been filed separately.

It is a general bug to assume that InputStream.read will read as many bytes as you believe are present; the actual return value may be any positive number up to the buffer size according to unpredictable platform-specific factors.
Comment 7 Jaroslav Tulach 2012-02-01 15:21:27 UTC
ergonomics#84239fe654ae
Comment 8 csesteban 2012-03-29 08:13:46 UTC
There is a workaround for this problem, I have this IO exception in 7.1.1 version.
Comment 9 Jesse Glick 2012-03-29 15:49:21 UTC
No workaround that I know of. Could probably be backported, especially if alexandru.stan can verify the fix (it may well occur only on Windows).
Comment 10 Jesse Glick 2012-04-17 12:11:10 UTC
*** Bug 211297 has been marked as a duplicate of this bug. ***
Comment 11 Jesse Glick 2012-04-18 12:11:45 UTC
As pointed out in bug #211297 comment #5, the attempted fix in fact just goes into an endless loop at org.netbeans.junit.NbModuleSuite$S.rewrite(NbModuleSuite.java:1146). Remember that the Javadoc for the read method states "...otherwise, no bytes are read and <code>0</code> is returned", yet the return value is checked only for -1, not 0.
Comment 12 Jesse Glick 2012-04-18 12:16:18 UTC
Created attachment 118451 [details]
Test case for endless loop

Reproducible on Linux / JDK 7. Unpack and run 'mvn integration-test'.
Comment 13 Jesse Glick 2012-04-18 12:19:24 UTC
Note that a similar loop in FileObject.asBytes uses a condition on the loop (pos < arr.length).
Comment 14 Jaroslav Tulach 2012-04-18 17:43:42 UTC
ergonomics#e8bc885e40e6
Comment 15 mbastian 2012-04-20 03:53:04 UTC
Is the fix deployed on the SNAPSHOT version of the plugin? I would like to try. Thanks.
Comment 16 Jesse Glick 2012-04-20 13:12:42 UTC
(In reply to comment #15)
> Is the fix deployed on the SNAPSHOT version of the plugin?

I doubt it. When the fix is in main sources and makes it into a development build, an automated notation should be added here (though it apparently did not work in the case of the initial fix, 84239fe654ae). Around that time the snapshot repo should be recreated.
Comment 17 Quality Engineering 2012-04-26 10:34:02 UTC
Integrated into 'main-golden', will be available in build *201204260400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e8bc885e40e6
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #207646: Reading a file into memory is not very clueless in Java6
Comment 18 Jesse Glick 2012-05-08 14:46:28 UTC
See bug #211297 comment #5 (and #6); the fix does not work at all, the loop simply spins forever. Both initial "read wrong amount" and endless loop reproducible even on Linux. I am looking into it.
Comment 19 Jesse Glick 2012-05-08 15:21:42 UTC
Never mind, the fix does work, the problem is that the snapshot repository is very old (20120424) so the fixed JAR is not being published. The only workaround is to build a Mavenized copy of the development version of this module for yourself; for example:

  ant -f nbjunit patch-for-maven

Having done that, the test case from comment #3 works for me on both Linux and XP (using JDK 7u4 in both cases).
Comment 20 Jesse Glick 2012-05-10 17:47:56 UTC
SNAPSHOT repo working for me now in Ubuntu. alexandru.stan, mbastian, csesteban - please mark VERIFIED if you can confirm on your own projects/repositories.
Comment 21 Jesse Glick 2012-05-10 17:49:40 UTC
To be clear, you will need <version>SNAPSHOT</version> of at least org.netbeans.api:org-netbeans-modules-nbjunit, available from

<repository>
    <id>netbeans-snapshot</id>
    <url>http://bits.netbeans.org/netbeans/trunk/maven-snapshot/</url>
</repository>