Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4514367
Votes 1
Synopsis javax.media.jai.JAI.getBuildVersion() is broken in applets
Category jai:implementation
Reported Against 1.1
Release Fixed 1.1.3-beta
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 12-OCT-2001
Description


java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

javax.media.jai.JAI.getBuildVersion() works okay in a standalone program,
returning a result like this:

    jai-1_1_1 Thu Sep 27 00:15:28 PDT 2001

But it fails to return useful information in an applet within a browser,
in which environment it says:

    JAI Build version unavailable.

We suspect that this is because the JAI tries to read some local files
to obtain the build version, which action violates the security model.
This behavior is, ah, less than ideal.  It means we cannot unambiguously
determine what version of the software our end-users are running, which
of course will probably lead to field support problems.

The information yielded by this routine should be hardcoded somewhere in
the .jar files of the extension, so an applet can access the build version.

Here is a sample applet that demonstrates the problem.

import java.awt.*;
import java.applet.*;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class VersionAppletJAI extends Applet{
        private boolean fontsSet = false;
        private String jvmMessage = " ", jaiMessage = " ";
        private Font f = new Font ("HELVETICA", Font.PLAIN, 12);
        private FontMetrics fm;
        private int dy, fHeight, x1, x2, y;

        public void init(){
                String java_version = java.lang.System.getProperty("java.version");
                try{
                        Class jaiClass = Class.forName("javax.media.jai.JAI");
                        Object jaiInstance = jaiClass.newInstance();
                        Method method = jaiClass.getMethod("getBuildVersion", null);
                        String jaiVersion = javax.media.jai.JAI.getBuildVersion();
                        // The problem is right here.  An applet always gets the
                        // following result, instead of useful information.
                        if (jaiVersion.equals("JAI Build version unavailable.")){
                            jaiMessage = "JAI 1.1 or higher is available with this JVM, but the exact version cannot be determined.";
                        }else{
                            jaiMessage = "You have " + jaiVersion + " associated with this JVM.";
                        }
                }catch(ClassNotFoundException ex){
                        jaiMessage = "You have no JAI associated with this JVM.";
                }catch(NoSuchMethodException ex){
                        jaiMessage = "You have no JAI 1.1.1 associated with this JVM.";
                }catch(InstantiationException ex){
                        jaiMessage = "JAI will not work with Java " + java_version + ".";
                }catch(IllegalAccessException ex){
                }catch(NoClassDefFoundError ex){
                        jaiMessage = "You have no JAI associated with this JVM.";
                }
                String java_vendor  = java.lang.System.getProperty("java.vendor");
                String JVM_Origin = getParameter ("JVM_Origin");
                jvmMessage = JVM_Origin + " is Java " + java_version + " from " + java_vendor;
        }

        public void restart(){
                repaint();
        }

        public void paint(Graphics g){
                g.setFont (f);
                Insets in = getInsets();
                Dimension d = getSize();
                if (!fontsSet){
                        fm = g.getFontMetrics(f);
                    dy = (fm.getAscent() - fm.getDescent()) / 2;
                    fHeight = fm.getHeight();
                    fontsSet = true;
                    int w1 = fm.stringWidth(jvmMessage);
                    int w2 = fm.stringWidth(jaiMessage);
                    int applet_width  = d.width  - in.right  - in.left;
                    int applet_height = d.height - in.bottom - in.top;
                    x1 = (applet_width - w1)/2;
                    x2 = (applet_width - w2)/2;
                    y = applet_height/2;
                }
                Rectangle clip = g.getClipBounds();
        g.setColor(new Color(240, 255, 240));
        g.fillRect(clip.x, clip.y, clip.width, clip.height);
                g.setColor(Color.black);
                g.drawString (jvmMessage, x1, y + dy - fHeight/2);
                g.drawString (jaiMessage, x2, y + dy + fHeight/2);
        }
}



(Review ID: 133603) 
======================================================================
Posted Date : 2005-11-23 22:51:33.0
Work Around
--- BEGIN ---   xxxxx@xxxxx   2002-08-08

Instead of JAI.getBuildVersion() use this

        Class jaiClass = Class.forName("javax.media.jai.JAI");
        Object jaiInstance = jaiClass.newInstance();
        String jaiVersion = jaiClass.getPackage().getImplementationVersion();

Apparently JAI.getBuildVersion() is rather superfluous.

--- END ---   xxxxx@xxxxx   2002-08-08
Evaluation
Problem as described. The issue is that JAI.class.getResourceAsStream("buildVersion") doesn't load the "buildVersion" file from the JAI jar files, if JAI is an installed extension in the main jre/lib directory (The javaplugin doesn't look in the ext diretory which seems to be a bug). JAI already has a workaround implemented (in PropertyUtil.getFileFromClasspath) to try to load the file from $java_home/ext/jai_core.jar. The fix here is to use that already implemented workaround if the primary JAI.class.getResourceAsStream("buildVersion") fails.
Posted Date : 2005-11-23 22:51:33.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang