Name: stC104175 Date: 03/08/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
getTime() for a JarEntry returns the wrong time. Try the following simple
application in JDK 1.2.2 and JDK 1.3RC1, you'll get an incorrect time, ie date,
from the 1.3 VM. Run the enclosed, click the button, select a jar file, and
then look at the output in sysout. I have looked into this and it is the
getTime that is returning a different value - it is not the date class.
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.jar.*;
import javax.swing.*;
public class JFrame1 extends javax.swing.JFrame
{
public JFrame1()
{
// This code is automatically generated by Visual Cafe when you
add
// components to the visual environment. It instantiates and
initializes
// the components. To modify the code, only use code syntax
that matches
// what Visual Cafe can generate, or Visual Cafe may be unable
to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
getContentPane().setLayout(null);
setSize(426,266);
setVisible(false);
JButton1.setText("Show the Bug in JDK 1.3");
getContentPane().add(JButton1);
JButton1.setBounds(72,36,269,163);
//}}
//{{INIT_MENUS
//}}
//{{REGISTER_LISTENERS
SymAction lSymAction = new SymAction();
JButton1.addActionListener(lSymAction);
//}}
}
public JFrame1(String sTitle)
{
this();
setTitle(sTitle);
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == JButton1)
JButton1_actionPerformed(event);
}
}
void JButton1_actionPerformed(java.awt.event.ActionEvent event)
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter
(new javax.swing.filechooser.FileFilter()
{
public boolean accept(File f)
{
if (f.isDirectory())
return true;
String lowerCaseName = f.getName
().toLowerCase();
return lowerCaseName.endsWith
(".jar");
}
public String getDescription()
{
return "Return Jars";
}
}
);
if (fileChooser.showOpenDialog(this) ==
JFileChooser.APPROVE_OPTION)
{
try
{
JarFile jarFile = new JarFile
(fileChooser.getSelectedFile());
try
{
for (Enumeration entries =
jarFile.entries();entries.hasMoreElements();)
{
try
{
JarEntry jarEntry =
(JarEntry)entries.nextElement();
long time =
jarEntry.getTime();
if (time != -1)
System.out.println(jarEntry.getName() + "'s time = " + new Date(time));
}
catch(ClassCastException e)
{
System.err.println
("Unexpected ClassCastException, trying to cast to JarEntry");
e.printStackTrace();
}
}
}
finally
{
jarFile.close();
}
}
catch(java.io.IOException e)
{
System.err.println("File could not be opened");
}
}
}
public void setVisible(boolean b)
{
if (b)
setLocation(50, 50);
super.setVisible(b);
}
static public void main(String args[])
{
(new JFrame1()).setVisible(true);
}
public void addNotify()
{
// Record the size of the window prior to calling parents
addNotify.
Dimension size = getSize();
super.addNotify();
if (frameSizeAdjusted)
return;
frameSizeAdjusted = true;
// Adjust size of frame according to the insets and menu bar
Insets insets = getInsets();
javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
int menuBarHeight = 0;
if (menuBar != null)
menuBarHeight = menuBar.getPreferredSize().height;
setSize(insets.left + insets.right + size.width, insets.top +
insets.bottom + size.height + menuBarHeight);
}
// Used by addNotify
boolean frameSizeAdjusted = false;
//{{DECLARE_CONTROLS
protected javax.swing.JButton JButton1 = new javax.swing.JButton();
//}}
//{{DECLARE_MENUS
//}}
}
(Review ID: 102198)
======================================================================
- duplicates
-
JDK-4309463 Jarsigner sets invalid file dates
-
- Closed
-