Path: blob/master/test/jdk/sun/net/www/protocol/jar/B4756443.java
41159 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 475644326* @summary REGRESSION: NPE in JarURLConnection.getLastModified after setUseCache(false)27*/2829import java.io.File;30import java.io.IOException;31import java.net.URL;32import java.net.URLConnection;3334public class B4756443 {3536public static void main(String [] args) throws IOException37{38String testsrc = System.getProperty ("test.src");39URL u;40if (testsrc == null || "".equals (testsrc)) {41/* not running in jtreg */42u = new URL ("jar:file:./foo.jar!/a/b/test.xml");43} else {44/* running in jtreg */45File f = new File(testsrc + File.separator46+ "foo.jar");47String s = f.toURL().toString();48u = new URL ("jar:" + s + "!/a/b/test.xml");49}50System.out.println ("Testing with: " + u);51URLConnection con = u.openConnection ();52con.setUseCaches (false);53con.connect ();54long l = con.getLastModified ();5556URLConnection con1 = u.openConnection ();57con1.setUseCaches (true);58con1.connect ();59long l1 = con1.getLastModified ();6061if (l != l1) {62throw new RuntimeException ("l != l1 ("+l+"/"+l1+")");63}64}65}666768