Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 209273 - dev-util/eclipse-sdk-3.4 : junit4 doesn't works due to hamcrest problem
Summary: dev-util/eclipse-sdk-3.4 : junit4 doesn't works due to hamcrest problem
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Java (show other bugs)
Hardware: AMD64 Linux
: High major (vote)
Assignee: Java team
URL:
Whiteboard:
Keywords:
Depends on: 287757 403161
Blocks: 296296
  Show dependency tree
 
Reported: 2008-02-07 17:30 UTC by mambro
Modified: 2015-04-20 21:43 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
class to test (Sum.java,70 bytes, text/plain)
2008-03-02 20:28 UTC, mambro
Details
test class (SumTest.java,330 bytes, text/plain)
2008-03-02 20:28 UTC, mambro
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mambro 2008-02-07 17:30:23 UTC
When i try to start a junit4 test in eclipse i get this error:

java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	... 19 more

I've tried to download the official eclipse package from eclipse's website and unpack it in my home. It works fine. This problem happens only with the eclipse installation from portage.

This is my eclipse-sdk installation

[I] dev-util/eclipse-sdk
     Available versions:  
	(3.2)	3.2.1-r2
	(3.3)	(~)3.3.1.1
	{branding cairo doc elibc_FreeBSD gnome opengl seamonkey}
     Installed versions:  3.2.1-r2(3.2)(19:08:24 03/02/2008)(cairo gnome opengl -branding -elibc_FreeBSD -seamonkey)
			  3.3.1.1(3.3)(14:53:43 07/02/2008)(-doc -elibc_FreeBSD)

This is hamcrest
[I] dev-java/hamcrest-core
     Available versions:  (~)1.1 {elibc_FreeBSD source}
     Installed versions:  1.1(18:23:57 07/02/2008)(-elibc_FreeBSD -source)
     Homepage:            http://code.google.com/p/hamcrest/
     Description:         Library of matchers for building test expressions.

This is my emerge --info

Portage 2.1.3.19 (default-linux/amd64/2007.0/desktop, gcc-4.1.2, glibc-2.6.1-r0, 2.6.23-gentoo-r6 x86_64)
=================================================================
System uname: 2.6.23-gentoo-r6 x86_64 Intel(R) Core(TM)2 Duo CPU E6750 @ 2.66GHz
Timestamp of tree: Thu, 07 Feb 2008 13:30:01 +0000
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.0.33-r1
dev-lang/python:     2.4.4-r6
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.10-r5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=nocona -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"
LANG="it_IT@.UTF-8@euro"
LC_ALL="it_IT.UTF-8@euro"
LINGUAS="it"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/mambro"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X aac aalib acl acpi alsa amd64 audiofile bash-completion berkdb bitmap-fonts bluetooth bzip2 cairo cddb cdr cli cracklib crypt cups dbus dri dv dvd dvdr dvdread emboss encode esd evo exif fam fbcon ffmpeg firefox flac foomaticdb fortran ftp gdbm gif gnome gnutls gphoto2 gpm gstreamer gtk hal iconv icq imagemagick ipod isdnlog jabber jack java javascript jikes joystick jpeg kdexdeltas kerberos ldap libcaca libnotify lm_sensors mad mhash midi mikmod mmx mp3 mpeg mplayer msn mudflap musicbrainz mysql ncurses nls nptl nptlonly nsplugin offensive ogg openal opengl openmp oss pam pcre pda pdf perl php plotutils png ppds pppd python qt3support quicktime readline reflection samba sdl session sox spell spl sse sse2 ssl svg symlink tcpd tetex theora tiff tk truetype truetype-fonts type1-fonts unicode usb vim-syntax vorbis wxwindows x264 xine xml xorg xosd xv xvid zlib" ALSA_CARDS="hda-intel" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="it" USERLAND="GNU" VIDEO_CARDS="vesa nv nvidia"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LDFLAGS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS


Reproducible: Always

Steps to Reproduce:
Comment 1 Vlastimil Babka (Caster) (RETIRED) gentoo-dev 2008-02-07 22:05:10 UTC
We have junit-4.4 which normally bundles the hamcrest-core classes but ours doesn't. And the eclipse-sdk build doesn't handle indirect deps well. Also looked at junit.jar bundled in eclipse sources and there are also no hamcrest classes, which means they use older version (hamcrest was added only in 4.4).

So in short, it needs to handle this indirect dep. But only Elvanor can know how :)
Comment 2 mambro 2008-03-02 18:43:51 UTC
Someone is working on the problem? There are some tests I can do to give a hand?
Comment 3 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-03-02 20:10:12 UTC
Yes, I handle this bug, and actually I will probably work on this this week

If you want to help, just create a junit4 test and attach it (as I never wrote junit tests yet). It should save me some time

Comment 4 mambro 2008-03-02 20:28:12 UTC
Created attachment 145133 [details]
class to test
Comment 5 mambro 2008-03-02 20:28:44 UTC
Created attachment 145135 [details]
test class
Comment 6 mambro 2008-03-02 20:30:28 UTC
Remember to add junit4 library to the classpath with right-click on the project -> Build Path -> Add Libraries -> JUnit4

Thank you
Comment 7 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-03-09 17:52:02 UTC
OK, I got to work on this today. Unfortunately I cannot reproduce, with your test files the test works OK (note that I dont have much experience with JUnit tests, I just right clicked on the file and chose Run as JUnit test).

This is strange because actually it should fail yes. We use the 4.4 junit version whereas Eclipse expects 4.3, and for 4.4 we do need the hamcrest dependency. I know how to fix this bug - only needs a test case to reproduce. So please try to provide me with some test that actually fail right now (maybe yours was too simplist so did not require hamcrest) and I'll fix it ASAP.
Comment 8 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-03-09 19:24:39 UTC
Can anyone reproduce this bug on x86?? ali_bush maybe?
Comment 9 Alistair Bush (RETIRED) gentoo-dev 2008-03-11 09:36:27 UTC
Works for me

Steps to Reproduce

1) Ok firstly.  Had to reemerge eclipse and its dependencies as eclipse blowing up.
2) Created project.  Added new class and new unit test.  Copied example into each respectively.
3) Right click on test, select Run > Run Test.
4) It runs :D
Comment 10 Alistair Bush (RETIRED) gentoo-dev 2008-03-11 09:37:48 UTC
Sorry for bugspam.

Versions of junit are

equery list junit
[ Searching for package 'junit' in all categories among: ]
 * installed packages
[I--] [ ~] dev-java/junit-3.8.2-r1 (0)
[I--] [ ~] dev-java/junit-4.4-r1 (4)
Comment 11 mambro 2008-04-08 15:48:19 UTC
I've manually added /usr/share/hamcrest-core/lib/hamcrest-core.jar to the build path and now it works..
Comment 12 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-04-09 16:23:01 UTC
What do you mean, you added hamcrest-core.jar to the build path? You mean the project build path?

That should still not be needed IMHO. So this is clearly a bug, but unfortunately I cannot reproduce it.


> I've manually added /usr/share/hamcrest-core/lib/hamcrest-core.jar to the build
> path and now it works..
> 

Comment 13 mambro 2008-04-09 16:33:06 UTC
Yes, I mean the project build path.
Comment 14 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-04-09 18:58:56 UTC
At LAST I can reproduce the bug. I had an old version of junit-4 laying around, that actually contained the hamcrest classes embedded.

So now that I can reproduce, I can fix it :)
Comment 15 Markus Kasper 2008-05-16 19:49:39 UTC
Hi,
same bug here on x86.
The bug occured on my laptop, but 2 other computers were not infected.
First I build on my laptop and another computer the junit package.
laptop -> /usr/share/junit-4/lib/junit.jar contains no hamcrest
other computer -> /usr/share/junit-4/lib/junit.jar contains hamcrest
( same junit-4 version, junit-4.4-r1 )

So, i checked, that both portage trees were up to date -> exact same ebuild for junit.

and then, i upgraded sun-jdk of the other computer from 1.6.0.03 to 1.6.0.05 and in junit.jar the hamcrest disappears, and the bug was on this computer, too.

So the problem is, with sun-jdk 1.6.0.03 hamcrest was integrated in junit.jar, with sun-jdk 1.6.0.05 there was no integration of hamcrest in junit.jar.

Perhaps this can help you.
Comment 16 Pun 2008-06-11 14:57:58 UTC
Same problem on x86. It started with the upgrade to sun-jdk/1.6.0.05 and can be worked around  by manual adding /usr/share/hamcrest-core/lib/hamcrest-core.jar to the project build path.
Comment 17 Dror Levin (RETIRED) gentoo-dev 2008-12-07 20:24:34 UTC
Has there been any progress? It's been more than 6 months since you said you'll fix it now that you can reproduce it, has something changed?
I'm still having this bug on eclipse 3.4.1 with junit 4.5.
Comment 18 Alistair Bush (RETIRED) gentoo-dev 2008-12-10 09:25:52 UTC
(In reply to comment #17)
> Has there been any progress? It's been more than 6 months since you said you'll
> fix it now that you can reproduce it, has something changed?
> I'm still having this bug on eclipse 3.4.1 with junit 4.5.
> 

I think you will find the reason for there being a lack of progress, is the difficulty of finding the solution.

This is the Workaround that ppl can use.

**********************************************
*************WORKAROUND***********************
**********************************************

Add the jar /usr/share/hamcrest-core/lib/hamcrest-core.jar to your build classpath for any projects using junit4 tests.

it could also be possible that you need /usr/share/hamcrest/lib/*.jar or other jars.  In which case adding them as well will work.

Comment 19 Jean-Noël Rivasseau (RETIRED) gentoo-dev 2008-12-10 09:38:01 UTC
Yes, people should use the workaround for now. Due to the way Gentoo currently packages hamcrest and JUnit, this bug is very hard to fix. At first I thought we could fix it just by manipulating OSGi manifests, but I mailed the Eclipse people and it looks like a patch to the Eclipse code is needed - which does not look easy to write. 
Comment 20 Joel 2010-03-02 17:17:57 UTC
This bug still exists on eclipse 3.5.1 (gentoo testing amd64)
Comment 21 Alistair Bush (RETIRED) gentoo-dev 2010-03-03 09:11:37 UTC
(In reply to comment #20)
> This bug still exists on eclipse 3.5.1 (gentoo testing amd64)
> 

Mmmm...  could you provide more information please.   Can you reproduce this with the attached Sum.java and SumTest.java.

I just used these and it worked.
Comment 22 Alistair Bush (RETIRED) gentoo-dev 2010-03-04 18:12:40 UTC
Ok so I was able to reproduce and now have a patch to fix for eclipse to fix this.
Comment 23 Alistair Bush (RETIRED) gentoo-dev 2010-03-05 17:25:24 UTC
Now working in eclipse-3.5.1-r1.  Need to file this upstream.   This defect will be closed after a 3.5 release is stable.
Comment 24 Alexander Vershilov (RETIRED) gentoo-dev 2010-09-04 15:00:39 UTC
I'm using netbeans 6.9 and same problem is there maybe problem is not in eclipse.
But in the way how junit is included in IDE.

Now I'm using workaround: adding hamcrest junit library`s build path. 
Comment 25 James Le Cuirot gentoo-dev 2015-04-20 21:43:14 UTC
This went stable long ago and is totally obsolete anyway.