src/share/classes/sun/applet/AppletPanel.java

Print this page




 777         final String serName = getSerializedObject();
 778         String code = getCode();
 779 
 780         if (code != null && serName != null) {
 781             System.err.println(amh.getMessage("runloader.err"));
 782 //          return null;
 783             throw new InstantiationException("Either \"code\" or \"object\" should be specified, but not both.");
 784         }
 785         if (code == null && serName == null) {
 786             String msg = "nocode";
 787             status = APPLET_ERROR;
 788             showAppletStatus(msg);
 789             showAppletLog(msg);
 790             repaint();
 791         }
 792         if (code != null) {
 793             applet = (Applet)loader.loadCode(code).newInstance();
 794             doInit = true;
 795         } else {
 796             // serName is not null;
 797             InputStream is = (InputStream)
 798                 java.security.AccessController.doPrivileged(
 799                                                             new java.security.PrivilegedAction() {
 800                                                                 public Object run() {
 801                                                                     return loader.getResourceAsStream(serName);
 802                                                                 }
 803                                                             });
 804             ObjectInputStream ois =
 805                 new AppletObjectInputStream(is, loader);
 806             Object serObject = ois.readObject();
 807             applet = (Applet) serObject;
 808             doInit = false; // skip over the first init
 809         }

 810 
 811         // Determine the JDK level that the applet targets.
 812         // This is critical for enabling certain backward
 813         // compatibility switch if an applet is a JDK 1.1
 814         // applet. [stanley.ho]
 815         findAppletJDKLevel(applet);
 816 
 817         if (Thread.interrupted()) {
 818             try {
 819                 status = APPLET_DISPOSE; // APPLET_ERROR?
 820                 applet = null;
 821                 // REMIND: This may not be exactly the right thing: the
 822                 // status is set by the stop button and not necessarily
 823                 // here.
 824                 showAppletStatus("death");
 825             } finally {
 826                 Thread.currentThread().interrupt(); // resignal interrupt
 827             }
 828             return null;
 829         }


1222             // checked before.
1223             Boolean jdk11Target = (Boolean) loader.isJDK11Target(appletClass);
1224             Boolean jdk12Target = (Boolean) loader.isJDK12Target(appletClass);
1225 
1226             // if applet JDK level has been checked before, retrieve
1227             // value and return.
1228             if (jdk11Target != null || jdk12Target != null) {
1229                 jdk11Applet = (jdk11Target == null) ? false : jdk11Target.booleanValue();
1230                 jdk12Applet = (jdk12Target == null) ? false : jdk12Target.booleanValue();
1231                 return;
1232             }
1233 
1234             String name = appletClass.getName();
1235 
1236             // first convert any '.' to '/'
1237             name = name.replace('.', '/');
1238 
1239             // append .class
1240             final String resourceName = name + ".class";
1241 
1242             InputStream is = null;
1243             byte[] classHeader = new byte[8];
1244 
1245             try {
1246                 is = (InputStream) java.security.AccessController.doPrivileged(
1247                     new java.security.PrivilegedAction() {
1248                         public Object run() {
1249                             return loader.getResourceAsStream(resourceName);
1250                         }
1251                     });
1252 
1253                 // Read the first 8 bytes of the class file
1254                 int byteRead = is.read(classHeader, 0, 8);
1255                 is.close();
1256 
1257                 // return if the header is not read in entirely
1258                 // for some reasons.
1259                 if (byteRead != 8)
1260                     return;
1261             }
1262             catch (IOException e)   {
1263                 return;
1264             }
1265 
1266             // Check major version in class file header
1267             int major_version = readShort(classHeader, 6);
1268 
1269             // Major version in class file is as follows:
1270             //   45 - JDK 1.1
1271             //   46 - JDK 1.2
1272             //   47 - JDK 1.3
1273             //   48 - JDK 1.4
1274             //   49 - JDK 1.5
1275             if (major_version < 46)




 777         final String serName = getSerializedObject();
 778         String code = getCode();
 779 
 780         if (code != null && serName != null) {
 781             System.err.println(amh.getMessage("runloader.err"));
 782 //          return null;
 783             throw new InstantiationException("Either \"code\" or \"object\" should be specified, but not both.");
 784         }
 785         if (code == null && serName == null) {
 786             String msg = "nocode";
 787             status = APPLET_ERROR;
 788             showAppletStatus(msg);
 789             showAppletLog(msg);
 790             repaint();
 791         }
 792         if (code != null) {
 793             applet = (Applet)loader.loadCode(code).newInstance();
 794             doInit = true;
 795         } else {
 796             // serName is not null;
 797             try (ObjectInputStream ois = new AppletObjectInputStream(
 798                     AccessController.doPrivileged((PrivilegedAction<InputStream>)() -> loader.getResourceAsStream(serName)),
 799                     loader)) {
 800 
 801                 applet = (Applet) ois.readObject();






 802                 doInit = false; // skip over the first init
 803             }
 804         }
 805 
 806         // Determine the JDK level that the applet targets.
 807         // This is critical for enabling certain backward
 808         // compatibility switch if an applet is a JDK 1.1
 809         // applet. [stanley.ho]
 810         findAppletJDKLevel(applet);
 811 
 812         if (Thread.interrupted()) {
 813             try {
 814                 status = APPLET_DISPOSE; // APPLET_ERROR?
 815                 applet = null;
 816                 // REMIND: This may not be exactly the right thing: the
 817                 // status is set by the stop button and not necessarily
 818                 // here.
 819                 showAppletStatus("death");
 820             } finally {
 821                 Thread.currentThread().interrupt(); // resignal interrupt
 822             }
 823             return null;
 824         }


1217             // checked before.
1218             Boolean jdk11Target = (Boolean) loader.isJDK11Target(appletClass);
1219             Boolean jdk12Target = (Boolean) loader.isJDK12Target(appletClass);
1220 
1221             // if applet JDK level has been checked before, retrieve
1222             // value and return.
1223             if (jdk11Target != null || jdk12Target != null) {
1224                 jdk11Applet = (jdk11Target == null) ? false : jdk11Target.booleanValue();
1225                 jdk12Applet = (jdk12Target == null) ? false : jdk12Target.booleanValue();
1226                 return;
1227             }
1228 
1229             String name = appletClass.getName();
1230 
1231             // first convert any '.' to '/'
1232             name = name.replace('.', '/');
1233 
1234             // append .class
1235             final String resourceName = name + ".class";
1236 

1237             byte[] classHeader = new byte[8];
1238 
1239             try (InputStream is = AccessController.doPrivileged(
1240                     (PrivilegedAction<InputStream>) () -> loader.getResourceAsStream(resourceName))) {





1241 
1242                 // Read the first 8 bytes of the class file
1243                 int byteRead = is.read(classHeader, 0, 8);

1244 
1245                 // return if the header is not read in entirely
1246                 // for some reasons.
1247                 if (byteRead != 8)
1248                     return;
1249             }
1250             catch (IOException e)   {
1251                 return;
1252             }
1253 
1254             // Check major version in class file header
1255             int major_version = readShort(classHeader, 6);
1256 
1257             // Major version in class file is as follows:
1258             //   45 - JDK 1.1
1259             //   46 - JDK 1.2
1260             //   47 - JDK 1.3
1261             //   48 - JDK 1.4
1262             //   49 - JDK 1.5
1263             if (major_version < 46)