Reputation: 2578
I have this trivial source code. I build it with JDK 6. The build goes fine with JDK 6 and produces two build artifacts: ./Class_B.class and subdir/Class_A.class.
public class Class_B extends Class_A {} (File ./Class_B.java)
public class Class_A {} (File ./subdir/Class_A.java)
Applying javah from JDK 6 passes, but javah from JDK 7+ fails:
$ /usr/lib/jvm/java-6-openjdk-amd64/bin/javah -d out -classpath . Class_B
$ /usr/lib/jvm/java-7-openjdk-amd64/bin/javah -d out -classpath . Class_B
Error: cannot access Class_A
class file for Class_A not found
BUT! It fails only till the modification time of Class_B.class is newer than of Class_B.java.
-rw-rw-r-- 1 aaa aaa 402 Jun 7 12:00 Class_B.class
-rwxr-xr-x 1 aaa aaa 139 Jun 7 11:56 Class_B.java
If I "touch" the .java then the new javah also passes!
-rw-rw-r-- 1 aaa aaa 402 Jun 7 12:00 Class_B.class
-rwxr-xr-x 1 aaa aaa 139 Jun 7 12:01 Class_B.java
$ /usr/lib/jvm/java-7-openjdk-amd64/bin/javah -d out -classpath . Class_B
$ echo $?
$ 0
On my opinion it makes sense to fail if the source is newer (the binary was not rebuilt).
However it behaves vice-versa: it's OK if the source is newer and fails unless -classpath .:subdir
is given if the source is older.
WHY??? Where is this change documented? I cannot find in javah documentation (for example: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javah.html) anything about this modification time check.
UPDATE: Explanation regarding possibility of using "javac -h":
javah
in JDK6 works even without -classpath .;./subdir
javah
in JDK7 conditionally works without -classpath .;./subdir
(depending on the modification time)javac -h
works only with -classpath .;./subdir
I am just interested to know about the difference between "1" and "2". "3" makes no sense, because it can't work without classpath at all.
Upvotes: 0
Views: 33