Posted on 2008-02-11 17:25:12-08 by chrei
Class not found when CLASSPATH option contains '#'
Hi,

the following behaviour occurs when setting the classpath through the CLASSPATH configuration option (on Linux with Perl 5.8.8 and up-to-date modules). It does not appear when setting it through the CLASSPATH env variable or a -cp option in EXTRA_JAVA_ARGS. The latter is a bad idea as it circumvents Inline::Java's internal classpath tweaking and in my app the use of the env variable has its own sort of problems ... so here I am.

This is how to reproduce it:

1. Create file Pod_alu.java containing the following well-known piece of java code and compile it into file Pod_alu.class:

public class Pod_alu { public Pod_alu(){ } public int add(int i, int j){ return i + j ; } public int subtract(int i, int j){ return i - j ; } }

2. Create two subdirectories named "sub-dir" and "sub#dir".

3. Copy the Pod_alu.class file in both subdirectories.

4. Run this piece of Perl code:

use Inline( Java => 'STUDY', CLASSPATH => 'sub#dir', STUDY => [ 'Pod_alu' ], ); use Inline::Java; my $alu = new Pod_alu() ; print($alu->add(9, 16) . "\n") ; # prints 25 print($alu->subtract(9, 16) . "\n") ; # prints -7

The code should display a message like

Class Pod_alu not found at /usr/lib/perl5/site_perl/5.8.8/i686-linux/Inline/Java.pm line 619 BEGIN failed--compilation aborted at p line 6, <GEN8> line 4.

When you change the CLASSPATH setting in the perl code from "sub#dir" to "sub-dir" it should work.

This behaviour is strange enough that I wanted to hear the forum's comments and having it reproduced by someone else before calling it a bug in Inline::Java. Java once had in fact a problem with '#' characters in the classpath (if I remember correctly back in 1.2 or even earlier) but that has long been fixed (at least I thought...).

Thanks for any comment.

Christian

Direct Responses: 7077 | Write a response
Posted on 2008-02-11 18:58:10-08 by patl in response to 7075
Re: Class not found when CLASSPATH option contains '#'
It's a bug in Inline::Java. Here's a quick patch for you:
Index: Java/sources/org/perl/inline/java/InlineJavaUserClassLoader.java =================================================================== RCS file: /cvsroot/inline-java/Inline-Java/Java/sources/org/perl/inline/java/InlineJavaUserClassLoa +der.java,v retrieving revision 1.2 diff -r1.2 InlineJavaUserClassLoader.java 36c36 < URL u = p.toURL() ; --- > URL u = p.toURI().toURL() ;
Basically the code uses a URLClassLoader and the path added is not properly escaped. I'll try and get that fixed in the next release. Patrick
Direct Responses: 7083 | Write a response
Posted on 2008-02-11 22:18:04-08 by chrei in response to 7077
Re: Class not found when CLASSPATH option contains '#'
Patrick,

thank you for the patch, things work flawlessly now.

When hunting that down a debug display of the complete classpath would have been very helpful, but I suspect this is not possible as it constitutes itself only on the "server" side and not on the "user" side.

BTW, I did some benchmarking between JavaServer and Inline::Java during the last days which brought a few results which surprised me a bit. Are you interested in hearing more on that?

Christian

Direct Responses: 7089 | Write a response
Posted on 2008-02-12 15:43:27-08 by patl in response to 7083
Re: Class not found when CLASSPATH option contains '#'
Sure, let me know what you found out.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.