Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335130

Summary: same program runs in command line but not in eclipse
Product: [Eclipse Project] JDT Reporter: quliang8247
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: minor    
Priority: P3 CC: Michael_Rennie, Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description quliang8247 CLA 2011-01-23 12:51:02 EST
Build Identifier: 20100917-0705

Exception thrown while running the following program in Eclipse using JVM 1.6.0 (MacOS default). The same program works fine in command line. It also works if the eclipse project JRE is set to Standard VM. 

/* 
* MacTest.java
*/
import javax.crypto.Mac;

public class MacTest {
	public static void main(String[] args) throws Exception {
		Mac mac = Mac.getInstance("HmacSHA1");
	}
}


Exception in thread "main" java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available
	at javax.crypto.Mac.getInstance(DashoA13*..)
	at MacTest.main(MacTest.java:6)

Reproducible: Always

Steps to Reproduce:
1. type the above program
2. in Run configuration->JRE, set jre to alternative -> JVM 1.6.0 (Mac OS default)
3. Run
Comment 1 Olivier Thomann CLA 2011-01-23 14:37:44 EST
It looks like you are missing some libraries on the classpath.
Comment 2 quliang8247 CLA 2011-01-23 22:43:12 EST
Thank you for your reply. 

I run the program again with -verbose:class option on to see which classes are loaded. It turned out that in Eclipse, the jar files loaded are exactly the same and even more, but it still fails. (On my machine, /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/ is a symbolic link to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/) 

Could it be the permission thing? Does Eclipse change the default configuration of the sandbox or something? Please help me find out the reason. Thanks.

====================================
The following is from the output.

COMMAND LINE:
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
...
[Opened /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar]

ECLIPSE:
[Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar]
...
[Opened /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar]
[Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/ui.jar]
[Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jsse.jar]
[Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jce.jar]
[Opened /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/charsets.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar]
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar]
Comment 3 Michael Rennie CLA 2013-08-13 00:35:34 EDT
If you try this code using an Oracle JRE does it work as expected? It could be that the Apple provided 1.6 JRE does not support that algorithm. 

According to the Oracle docs it does support HmacSHA1: http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html#SunJCEProvider
Comment 4 Michael Rennie CLA 2013-09-11 09:49:27 EDT
Closing as NOT_ECLIPSE, since it appears to be a configuration issue