2727import java .security .cert .X509Certificate ;
2828import java .util .Date ;
2929import java .util .Locale ;
30+ import java .util .TimeZone ;
3031
3132import jdk .test .lib .process .OutputAnalyzer ;
3233import jdk .test .lib .util .JarUtils ;
@@ -46,6 +47,7 @@ public class NoTimestampTest extends Test {
4647 * and checks that proper warnings are shown.
4748 */
4849 public static void main (String [] args ) throws Throwable {
50+
4951 Locale reservedLocale = Locale .getDefault ();
5052 Locale .setDefault (Locale .US );
5153
@@ -61,6 +63,9 @@ public static void main(String[] args) throws Throwable {
6163 private void start () throws Throwable {
6264 String timezone = System .getProperty ("user.timezone" );
6365 System .out .println (String .format ("Timezone = %s" , timezone ));
66+ if (timezone != null ) {
67+ TimeZone .setDefault (TimeZone .getTimeZone (timezone ));
68+ }
6469
6570 // create a jar file that contains one class file
6671 Utils .createFiles (FIRST_FILE );
@@ -73,10 +78,11 @@ private void start() throws Throwable {
7378 "-validity" , Integer .toString (VALIDITY ));
7479
7580 Date expirationDate = getCertExpirationDate ();
81+ System .out .println ("Cert expiration: " + expirationDate );
7682
7783 // sign jar file
7884 OutputAnalyzer analyzer = jarsigner (
79- "-J-Duser. timezone=" + timezone ,
85+ userTimezoneOpt ( timezone ) ,
8086 "-keystore" , KEYSTORE ,
8187 "-storepass" , PASSWORD ,
8288 "-keypass" , PASSWORD ,
@@ -90,7 +96,7 @@ private void start() throws Throwable {
9096
9197 // verify signed jar
9298 analyzer = jarsigner (
93- "-J-Duser. timezone=" + timezone ,
99+ userTimezoneOpt ( timezone ) ,
94100 "-verify" ,
95101 "-keystore" , KEYSTORE ,
96102 "-storepass" , PASSWORD ,
@@ -103,7 +109,7 @@ private void start() throws Throwable {
103109
104110 // verify signed jar in strict mode
105111 analyzer = jarsigner (
106- "-J-Duser. timezone=" + timezone ,
112+ userTimezoneOpt ( timezone ) ,
107113 "-verify" ,
108114 "-strict" ,
109115 "-keystore" , KEYSTORE ,
@@ -117,6 +123,10 @@ private void start() throws Throwable {
117123 System .out .println ("Test passed" );
118124 }
119125
126+ private static String userTimezoneOpt (String timezone ) {
127+ return timezone == null ? null : "-J-Duser.timezone=" + timezone ;
128+ }
129+
120130 private static Date getCertExpirationDate () throws Exception {
121131 KeyStore ks = KeyStore .getInstance ("JKS" );
122132 try (InputStream in = new FileInputStream (KEYSTORE )) {
0 commit comments