Bug 383122 - Launching RMI client application gives error "unknown protocol: rsrc
Summary: Launching RMI client application gives error "unknown protocol: rsrc
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2012-06-20 11:54 EDT by Fabian Zeindl CLA
Modified: 2012-06-21 09:23 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Zeindl CLA 2012-06-20 11:54:06 EDT
Build Identifier: 20120216-1857

Hi,

 i have an RMI-client-application which worked perfectly until a few months ago. When i package it into a jar (with jarInJarloader or without) it works flawlessly, but when i push the "Run" button in Eclipse it can't connect to the server anymore with a MalformedURLException, when i do Naming.lookup()




Reproducible: Always
Comment 1 Tomasz Zarna CLA 2012-06-20 12:08:14 EDT
This doesn't seem to be related to JDT/Core. Nevertheless, could you please provide more details like the exception stack trace, so we could try to move the bug to a more accurate inbox.
Comment 2 Fabian Zeindl CLA 2012-06-20 12:59:18 EDT
This is the code (RMIInterface and DBInterface are my objects).

public final class MainTest {

	public static void main(final String args[]) {
		try {
			RMIInterface rmiInt = (RMIInterface) Naming.lookup("rmi://<server>:<port>/DBInterface");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

This is the stacktrace:

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
	java.net.MalformedURLException: unknown protocol: rsrc
	at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
	at java.rmi.Naming.lookup(Naming.java:84)
	at at.busta.rsystem.client.MainTest.main(MainTest.java:20)
Caused by: java.net.MalformedURLException: unknown protocol: rsrc
	at java.net.URL.<init>(URL.java:574)
	at java.net.URL.<init>(URL.java:464)
	at java.net.URL.<init>(URL.java:413)
	at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:749)
	at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:507)
	at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
	at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
	at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
	at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
Comment 3 Ayushman Jain CLA 2012-06-20 13:36:30 EDT
Looks like your URL "rmi://<server>:<port>/DBInterface" is not correct. You will get the same exception even if you run outside of eclipse. This is clearly not an eclipse bug. Closing.
Comment 4 Fabian Zeindl CLA 2012-06-20 13:44:44 EDT
Do you honestly think i would report a bug then? i DON'T get this error when i'm running outside eclipse, it's WORKING fine. I've used this URL for the last 7 years in production!
Comment 5 Fabian Zeindl CLA 2012-06-20 13:51:46 EDT
Also this bug is all over the internet:

http://stackoverflow.com/questions/7507156/java-net-malformedurlexception-unknown-protocol-rsrc
https://www.google.at/#hl=en&sclient=psy-ab&q=eclipse+unknown+protocol+rsrc&oq=eclipse+unknown+protocol+rsrc&aq=f&aqi=&aql=&gs_l=hp.3...160.10313.0.10433.52.39.9.0.0.1.241.4766.14j22j3.39.0.eiatsh..0.0.FAiIRcE97pk&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=f75f7aff5578b394&biw=1390&bih=783

Only so far the only solutions i've found concern the classloader which is used when you export a Jar from eclipse. The solution the say is to use fat-jar instead of eclipse-export. My problem is that my jar works fine (just tested again), only inside of eclipse it doesn't work.

Tested today (again) on Mac and Windows.
Comment 6 Satyam Kandula CLA 2012-06-21 00:06:07 EDT
rsrc protocol is used by the jarInJarloader when it is packaged as a runnable jar. The jarInJarLoader has code to take care of this protocol and hence you are probably not having this problem when you make it a runnable jar. 

Normal 'Run' from Eclipse shouldn't fall in this category. Is your RMI-server application created using 'package into the jar using jarInJarloader'?
Comment 7 Dani Megert CLA 2012-06-21 03:09:41 EDT
What was the version where it worked and which one are you now using (3.7.2)?

When you run inside Eclipse, are you using the Eclipse exported JAR or just the source?

The easiest would be to provide a self-contained example.
Comment 8 Fabian Zeindl CLA 2012-06-21 07:03:07 EDT
@Satyam: Yes, my server-application uses org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

@Dani: I'm working with SWT version 3.7.2 if that's what you mean. Eclipse version is Indigo.

Now that i think of it i have to admit that i'm not sure it ever worked from within eclipse. I transitioned to eclipse from vim/screen with the Helios release. I thought it worked, but i didn't have the code in my hands for the last few months. Sorry for that misinformation.
Comment 9 Fabian Zeindl CLA 2012-06-21 07:03:32 EDT
The server application runs per jar on the command-line btw. No eclipse or anything involved.
Comment 10 Dani Megert CLA 2012-06-21 07:05:20 EDT
(In reply to comment #8)
> @Satyam: Yes, my server-application uses
> org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

With "uses" you mean, your code references that class?
Comment 11 Fabian Zeindl CLA 2012-06-21 07:07:41 EDT
No it means that i build a jar out of the code using this ant-file:


    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project default="create_run_jar">

    	<target name="create_run_jar">
    		<jar destfile="server.jar">
    			<manifest>
    				<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
    				<attribute name="Rsrc-Main-Class" value="server.Main" />
    				<attribute name="Class-Path" value="." />
    				<attribute name="Rsrc-Class-Path" value="./ log4j-1.2.16.jar glazedlists-1.8.0fab1an-3.jar gson-2.2.jar guava-12.0.jar postgresql-9.1-902.jdbc4.jar" />
    			</manifest>
    			<zipfileset src="jar-in-jar-loader.zip" />
    			<fileset dir="build" />
    			<zipfileset dir="/Users/fabian/dev/rsys-server/lib" includes="log4j-1.2.16.jar" />
    			<zipfileset dir="/Users/fabian/dev/rsys-server/lib" includes="glazedlists-1.8.0fab1an-3.jar" />
    			<zipfileset dir="/Users/fabian/dev/rsys-server/lib" includes="gson-2.2.jar" />
    			<zipfileset dir="/Users/fabian/dev/rsys-server/lib" includes="guava-12.0.jar" />
    			<zipfileset dir="/Users/fabian/dev/rsys-server/lib" includes="postgresql-9.1-902.jdbc4.jar" />
    		</jar>
    	</target>
    </project>

I don't reference any ClassLoaders, SecurityManager or the like in my code.
Comment 12 Dani Megert CLA 2012-06-21 07:15:48 EDT
Right. So you rely on the functionality of the JarRsrcLoader. This can't work inside Eclipse unless you make a launch configuration that also refers to that class loader or you unzip the packaged files.
Comment 13 Fabian Zeindl CLA 2012-06-21 07:19:51 EDT
I don't know what you mean with "rely" on the functionality. I don't i just use it to build jars for deployment. I used to built these jars WITHOUT the JarInJarLoader and they still would work. The JarInJarLoader isn't referenced anywhere except in the build-file, differently speaking: I can delete the jar-in-jar-loader.zip and the build-file and it still wouldn't work in Eclipse.
Comment 14 Fabian Zeindl CLA 2012-06-21 07:20:26 EDT
Sigh, how often do i have to reopen this?
Comment 15 Fabian Zeindl CLA 2012-06-21 07:21:42 EDT
When i press the RUN button in Eclipse, it doesn't build a jar in my understanding. ALL i want is my code to run from inside Eclipse, and i have no idea why it doesn't (and a lot of people on the internet don't have an idea either). I guess it's got something to do with RMI-code loading that is fuc$ed up by Eclipse.
Comment 16 Dani Megert CLA 2012-06-21 07:29:19 EDT
(In reply to comment #15)
> When i press the RUN button in Eclipse, it doesn't build a jar in my
> understanding. ALL i want is my code to run from inside Eclipse, and i have no
> idea why it doesn't (and a lot of people on the internet don't have an idea
> either). I guess it's got something to do with RMI-code loading that is fuc$ed
> up by Eclipse.

Maybe because some parts of your app are already zipped/JARed? Java cannot handle that. This is what the JarInJarLoader is used for.

>I don't know what you mean with "rely" on the functionality. I don't i just 
>use
>it to build jars for deployment. I used to built these jars WITHOUT the
>JarInJarLoader and they still would work.
But your Ant script in comment 11 does.

Please
- attach a (demo) project or workspace that works outside Eclipse when exported
- provide the steps you use to export (which do not involve the JarInJarLoader)
- the launch configuration which fails inside Eclipse

Without that information we can't help you no matter whether we keep this bug open or not.
Comment 17 Satyam Kandula CLA 2012-06-21 08:39:04 EDT
(In reply to comment #13)
> I don't know what you mean with "rely" on the functionality. I don't i just use
> it to build jars for deployment. I used to built these jars WITHOUT the
> JarInJarLoader and they still would work. The JarInJarLoader isn't referenced
> anywhere except in the build-file, differently speaking: I can delete the
> jar-in-jar-loader.zip and the build-file and it still wouldn't work in Eclipse.

I don't understand the underlying mechanism of the RMI, but here is what I think is happening. The server component is sending some information of the class which is having the class name as rsrc url. This is probably because of the way the jarInJarLoader works. Now, the client code which doesn't understand this rsrc url, is failing with this error.

Make the server and client both based on the JarInJarLoader or both 'not'. I don't know if this is a solution or if this is a workaround :), but I think it should work.
Comment 18 Fabian Zeindl CLA 2012-06-21 08:49:55 EDT
Thank you, thank you, thank you and Kudos. This seems to be the problem. When I build the server without the JarInJar-stuff, it works.