Example usage for java.lang System getSecurityManager

List of usage examples for java.lang System getSecurityManager

Introduction

In this page you can find the example usage for java.lang System getSecurityManager.

Prototype

public static SecurityManager getSecurityManager() 

Source Link

Document

Gets the system-wide security manager.

Usage

From source file:org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean.java

/**
 * Registration method.//from w w w .j  a v a2s.com
 * 
 * @param classes
 * @param serviceProperties
 * @return the ServiceRegistration
 */
ServiceRegistration registerService(Class<?>[] classes, final Dictionary serviceProperties) {
    Assert.notEmpty(classes, "at least one class has to be specified for exporting "
            + "(if autoExport is enabled then maybe the object doesn't implement any interface)");

    // create an array of classnames (used for registering the service)
    final String[] names = ClassUtils.toStringArray(classes);
    // sort the names in alphabetical order (eases debugging)
    Arrays.sort(names);

    log.info("Publishing service under classes [" + ObjectUtils.nullSafeToString(names) + "]");

    ServiceFactory serviceFactory = new PublishingServiceFactory(resolver, classes,
            (ExportContextClassLoaderEnum.SERVICE_PROVIDER.equals(contextClassLoader)), classLoader,
            aopClassLoader, bundleContext);

    if (isBeanBundleScoped())
        serviceFactory = new OsgiBundleScope.BundleScopeServiceFactory(serviceFactory);

    if (System.getSecurityManager() != null) {
        AccessControlContext acc = SecurityUtils.getAccFrom(beanFactory);
        final ServiceFactory serviceFactoryFinal = serviceFactory;
        return AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
            public ServiceRegistration run() {
                return bundleContext.registerService(names, serviceFactoryFinal, serviceProperties);
            }
        }, acc);
    } else {
        return bundleContext.registerService(names, serviceFactory, serviceProperties);
    }
}

From source file:org.apache.catalina.session.PersistentManagerBase.java

/**
 * Clear all sessions from the Store.//w  w w  . jav  a  2s. c o  m
 */
public void clearStore() {

    if (store == null)
        return;

    try {
        if (System.getSecurityManager() != null) {
            try {
                AccessController.doPrivileged(new PrivilegedStoreClear());
            } catch (PrivilegedActionException ex) {
                Exception exception = ex.getException();
                log.error("Exception clearing the Store: " + exception);
                exception.printStackTrace();
            }
        } else {
            store.clear();
        }
    } catch (IOException e) {
        log.error("Exception clearing the Store: " + e);
        e.printStackTrace();
    }

}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.java

/**
 * Cancel waiting due to timeout.//from   ww w.  j a v a  2s .c  om
 */
private void timeout() {
    ApplicationContextException e;
    List<OsgiServiceDependencyEvent> events = null;
    String filterAsString = null;

    synchronized (monitor) {
        // deregister listener to get an accurate snapshot of the
        // unsatisfied dependencies.

        if (dependencyDetector != null) {
            dependencyDetector.deregister();
            events = dependencyDetector.getUnsatisfiedDependenciesAsEvents();
            filterAsString = dependencyDetector.createUnsatisfiedDependencyFilter();
        }
    }

    Filter filter = (filterAsString != null ? OsgiFilterUtils.createFilter(filterAsString) : null);

    log.warn("Timeout occurred before finding service dependencies for [" + delegateContext.getDisplayName()
            + "]");

    String bundleName = null;
    if (System.getSecurityManager() != null) {
        bundleName = AccessController.doPrivileged(new PrivilegedAction<String>() {
            public String run() {
                return OsgiStringUtils.nullSafeSymbolicName(getBundle());
            }
        });
    } else {
        bundleName = OsgiStringUtils.nullSafeSymbolicName(getBundle());
    }

    // generate exception
    e = new ApplicationContextException("Application context " + "initialization for '" + bundleName
            + "' has timed out waiting for " + filterAsString);
    e.fillInStackTrace();

    // send notification
    delegatedMulticaster.multicastEvent(new BootstrappingDependenciesFailedEvent(delegateContext,
            delegateContext.getBundle(), e, events, filter));

    fail(e, true);
}

From source file:com.ixora.rms.ui.RMSFrame.java

/**
 * Display the main window of the application to the user.
 * @throws FailedToSaveConfiguration/*from www . ja v  a 2  s .  com*/
 * @throws SocketException
 * @throws RMSException
 */
private static void initApplication() throws SocketException, FailedToSaveConfiguration, RMSException {
    // first thing to do:
    // initialize the message repository, set the default
    // repository to the repository for the main application component
    MessageRepository.initialize(RMSComponent.NAME);

    // assign a public IP address for the console to use
    String currentConsoleIpAddress = ConfigurationMgr.getString(RMSComponent.NAME,
            RMSConfigurationConstants.NETWORK_ADDRESS);
    if (Utils.isEmptyString(currentConsoleIpAddress)) {
        // tell RMI to use the fully qualified name for this host
        // for object references
        System.setProperty("java.rmi.server.useLocalHostname", "true");
    } else {
        System.setProperty("java.rmi.server.hostname", currentConsoleIpAddress);
    }

    // register deployment modules with the update manager
    UpdateMgr.registerModule(new IxoraCommonModule());
    UpdateMgr.registerModule(new RMSModule());
    UpdateMgr.registerNodeModule(new IxoraCommonModule());
    UpdateMgr.registerNodeModule(new RMSModule());

    // ConfigurationMgr.makeConfigurationEditable(PreferencesConfigurationConstants.PREFERENCES);
    ConfigurationMgr.makeConfigurationEditable(RMSComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(DataViewBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ChartsBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(TablesBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(PropertiesBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(LogBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(LogComponent.NAME);
    //      ConfigurationMgr.makeConfigurationEditable(LogComponentDB.NAME);
    // ConfigurationMgr.makeConfigurationEditable(LogComponentXML.NAME);
    ConfigurationMgr.makeConfigurationEditable(MonitoringSessionRepositoryComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(JobsComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ReactionsComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ReactionsEmailComponent.NAME);
    // ConfigurationMgr.makeConfigurationEditable(UpdateComponent.NAME);

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new java.rmi.RMISecurityManager());
    }

    try {
        // initialize RMS
        RMS.initialize();
    } catch (Exception e) {
        // this could happen if a special IP address has been assigned to
        // the console has changed since last time the app was started
        if (e.getCause() instanceof ExportException || Utils.getTrace(e).toString().contains("Port")) {
            logger.error("Ignoring the ip address assigned to the console " + currentConsoleIpAddress
                    + " as it seems to be invalid.");
            resetConsoleIpAddress();
            // try again
            RMS.initialize();
        } else {
            throw new AppRuntimeException(e);
        }
    }

    // do a quick ping to website to check for updates
    UpdateMgr.checkForUpdates();

    // build the GUI on the event dispatch thread
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                // install UI factory in the commons library
                UIFactoryMgr.installUIFactory(new RMSUIFactory());
                // JDialog.setDefaultLookAndFeelDecorated(true);
                // JFrame.setDefaultLookAndFeelDecorated(true);
                // Toolkit.getDefaultToolkit().setDynamicLayout(true);
                Toolkit.getDefaultToolkit().setDynamicLayout(false);
                AppFrameParameters params = new AppFrameParameters();
                params.setString(AppFrameParameters.LOOK_AND_FEEL_CLASS,
                        "javax.swing.plaf.metal.MetalLookAndFeel");
                //"com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
                params.setString(AppFrameParameters.FEEDBACK_URL,
                        "http://spreadsheets.google.com/formResponse");
                JFrame frame = new RMSFrame(params);
                UIUtils.maximizeFrameAndShow(frame);
            } catch (Throwable e) {
                logger.error(e);
                System.exit(1);
            }
        }
    });
}

From source file:com.symbian.driver.launch.DriverLaunch.java

/**
 * creatJob : create an eclipse Job/*from  w w  w . ja v a  2 s  .  c o  m*/
 * 
 * @param Task
 *            aTask : The root task to run
 * @param int
 *            aNumberOfTasks : the number of tasks to run
 * @param boolean
 *            aIsBuild : true = build, false = run
 * 
 * @param boolean
 *            aClearConsole : clear the console. This will be used for
 *            build+run to keep the console between jobs.
 * @return Job
 */
public Job createJob(final ILaunchConfiguration aLaunchConfig, final boolean aIsBuild,
        final boolean aCleanConsole, final boolean aKeepLog) {

    final Job lJob = new Job("Test Driver Job") {

        private Logger LOGGER;

        private Task lTask = null;

        protected IStatus run(final IProgressMonitor aProgressMonitor) {

            class ProgressMonitorThread extends Thread {

                private IProgressMonitor iProgressMonitor = aProgressMonitor;
                private boolean isDone = false;

                public void run() {
                    while (!isDone) {
                        if (iProgressMonitor.isCanceled()) {
                            DeviceUtils.stopPoll();
                            break;
                        }
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException ignore) {
                        }
                    }
                }

                public void done() {
                    isDone = true;
                }
            }
            ;

            ProgressMonitorThread lProgressCancel = new ProgressMonitorThread();
            lProgressCancel.start();

            // configure logging again this will happen when the job starts
            TDGUIConfigLogging lLogConf = TDGUIConfigLogging.getInstance();
            lLogConf.configureLogging(aKeepLog);

            UIUtils.getDisplay().asyncExec(new ShowView());

            LOGGER = Logger.getLogger(Job.class.getName());

            LOGGER.info("\n\n*******Starting Job : " + this.getName());

            // configure TestDriver from Preferences and launch
            // configuration
            try {
                TestDriverConfigurator.configTestDriver(aLaunchConfig);
            } catch (ParseException lParseException) {
                return new Status(IStatus.ERROR, DriverEditorPlugin.ID, IStatus.ERROR,
                        this.getName() + " failed to set TestDriver configuration, see TestDriver log file.",
                        lParseException);
            }

            TDConfig CONFIG = TDConfig.newInstance();

            try {
                CONFIG.printConfig(true);
            } catch (IOException lException) {
                LOGGER.log(Level.SEVERE, lException.getMessage(), lException);
            }

            // try to load the driver file and get the task for real.
            try {
                ResourceLoader.resetResourceSet();
                lTask = ResourceLoader.load();
            } catch (ParseException lPex) {
                // log and error and finish the Job
                LOGGER.log(Level.SEVERE, "Failed to load resource : " + lPex.getMessage(), lPex);
                return new Status(IStatus.ERROR, DriverEditorPlugin.ID, IStatus.ERROR,
                        this.getName() + " failed to load the driver file, please check your configuration.",
                        lPex);
            }

            if (lTask == null) {
                return new Status(IStatus.ERROR, DriverEditorPlugin.ID, IStatus.ERROR,
                        this.getName()
                                + " --- failed to find the requested suite, please check your configuration.",
                        null);
            }
            int lNumberOfTasks = 1;

            for (Iterator lTaskIter = lTask.eAllContents(); lTaskIter.hasNext();) {
                Object lObject = lTaskIter.next();
                // this list must much the visitor listerners we are passing
                // in the job.
                if (aIsBuild) {
                    if (lObject instanceof Task || lObject instanceof CmdPC || lObject instanceof Build
                            || lObject instanceof TestExecuteScript || lObject instanceof Transfer
                            || lObject instanceof Reference || lObject instanceof CmdSymbian
                            || lObject instanceof Rtest) {
                        lNumberOfTasks++;
                    }
                } else {
                    if (lObject instanceof Task || lObject instanceof TestExecuteScript
                            || lObject instanceof Transfer || lObject instanceof Reference
                            || lObject instanceof CmdSymbian || lObject instanceof Rtest) {
                        lNumberOfTasks++;
                    }
                }
            }
            // add parent levels
            lNumberOfTasks = lNumberOfTasks + lTask.getLevel();

            aProgressMonitor.beginTask((aIsBuild ? "Building" : "Running") + " task " + lTask.getName(),
                    lNumberOfTasks);

            final Visitor lVisitor;

            if (aIsBuild) {
                lVisitor = new PCVisitor();
                ((PCVisitor) lVisitor).setRBuild(iRBuild);
            } else {
                lVisitor = new SymbianVisitor();
            }

            // show the Test Result view

            UIUtils.getDisplay().asyncExec(new Runnable() {
                public void run() {
                    TestViewer.getInstance().setInput(lVisitor.getResult().getReport());
                }
            });

            lVisitor.addVisitorListener(new IVisitorEventListener() {

                public void taskFinished(TaskFinishedEvent aVisitorEvent) {

                    EObject lVisitObject = aVisitorEvent.getEObject();
                    if (lVisitObject instanceof Task) {
                        aProgressMonitor.subTask("Finished task: " + ((Task) lVisitObject).getName());
                    } else if (lVisitObject instanceof CmdPC) {
                        aProgressMonitor
                                .subTask("Finished Running PC command: " + ((CmdPC) lVisitObject).getURI());
                    } else if (lVisitObject instanceof Build) {
                        aProgressMonitor
                                .subTask("Finished Building group dir: " + ((Build) lVisitObject).getURI());
                    } else if (lVisitObject instanceof TestExecuteScript) {
                        if (aIsBuild) {
                            aProgressMonitor.subTask("Finished Copying TEF Script to repository: "
                                    + ((TestExecuteScript) lVisitObject).getPCPath());
                        } else {
                            aProgressMonitor.subTask("Finished Running TEF Script: "
                                    + ((TestExecuteScript) lVisitObject).getPCPath());
                        }
                    } else if (lVisitObject instanceof Transfer) {
                        if (aIsBuild) {
                            aProgressMonitor.subTask("Finished Copying Transfer file to repository: "
                                    + ((Transfer) lVisitObject).getPCPath());
                        } else {
                            aProgressMonitor.subTask("Finished Retrieve file to results: "
                                    + ((Transfer) lVisitObject).getPCPath());
                        }
                    } else if (lVisitObject instanceof Reference) {
                        aProgressMonitor.subTask(
                                "Finished Reference: " + ((Reference) lVisitObject).getUri().getName());
                    } else if (lVisitObject instanceof CmdSymbian) {
                        aProgressMonitor.subTask("Finished Running Symbian command: "
                                + ((CmdSymbian) lVisitObject).getStatCommand().getLiteral());
                    } else if (lVisitObject instanceof Rtest) {
                        aProgressMonitor
                                .subTask("Finished Running RTest: " + ((Rtest) lVisitObject).getSymbianPath());
                    }

                    aProgressMonitor.worked(1);
                    // if the job has been canceled, ask the visistor to
                    // stop at the end of the task
                    if (aProgressMonitor.isCanceled()) {
                        lVisitor.stop();
                    }

                }

                public void taskStarted(TaskStartedEvent aVisitorEvent) {
                    EObject lVisitObject = aVisitorEvent.getEObject();
                    if (lVisitObject instanceof Task) {
                        aProgressMonitor.subTask("Started task: " + ((Task) lVisitObject).getName());
                    } else if (lVisitObject instanceof CmdPC) {
                        aProgressMonitor
                                .subTask("Started Running PC command: " + ((CmdPC) lVisitObject).getURI());
                    } else if (lVisitObject instanceof Build) {
                        aProgressMonitor
                                .subTask("Started Building group dir: " + ((Build) lVisitObject).getURI());
                    } else if (lVisitObject instanceof TestExecuteScript) {
                        if (aIsBuild) {
                            aProgressMonitor.subTask("Started Copying TEF Script to repository: "
                                    + ((TestExecuteScript) lVisitObject).getPCPath());
                        } else {
                            aProgressMonitor.subTask("Started Running TEF Script: "
                                    + ((TestExecuteScript) lVisitObject).getPCPath());
                        }
                    } else if (lVisitObject instanceof Transfer) {
                        if (aIsBuild) {
                            aProgressMonitor.subTask("Started Copying Transfer file to repository: "
                                    + ((Transfer) lVisitObject).getPCPath());
                        } else {
                            aProgressMonitor.subTask("Started Retrieve file to results: "
                                    + ((Transfer) lVisitObject).getPCPath());
                        }
                    } else if (lVisitObject instanceof Reference) {
                        aProgressMonitor
                                .subTask("Started Reference: " + ((Reference) lVisitObject).getUri().getName());
                    } else if (lVisitObject instanceof CmdSymbian) {
                        aProgressMonitor.subTask("Started Running Symbian command: "
                                + ((CmdSymbian) lVisitObject).getStatCommand().getLiteral());
                    } else if (lVisitObject instanceof Rtest) {
                        aProgressMonitor
                                .subTask("Started Running RTest: " + ((Rtest) lVisitObject).getSymbianPath());
                    }
                }
            });

            try {
                // set our security manager to disallow TestDriver to kill the
                // JVM with system.exit()

                SecurityManager lSec = System.getSecurityManager();
                LOGGER.fine("Installing Security Manager around Test Driver.");
                System.setSecurityManager(new TestDriverRunnerSecurityManager());
                lVisitor.start(lTask);

                // remove security manager
                LOGGER.fine("Removing Security Manager");
                System.setSecurityManager(lSec);

            } catch (SecurityException lSecException) {
                // ignore security exception. TestDriver has System.exit()
            }

            aProgressMonitor.done();
            lProgressCancel.done();

            return new Status(IStatus.OK, DriverEditorPlugin.ID, IStatus.OK,
                    "TestDriver " + (aIsBuild ? "Build" : "Run") + " Finished ", null);
        }
    };

    lJob.setUser(true);
    lJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);

    return lJob;
}

From source file:org.apache.jasper.runtime.PageContextImpl.java

public void removeAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer.getMessage("jsp.error.attribute.null_name"));
    }/*from w w  w . j a v a2s .  c o m*/

    if (System.getSecurityManager() != null) {
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                doRemoveAttribute(name);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name);
    }
}

From source file:org.apache.myfaces.shared_ext202patch.util.StateUtils.java

/**
 * Performs deserialization with the serialization provider created from the
 * SerialFactory.// www .j a  va2  s .c om
 * 
 * @param bytes
 * @param ctx
 * @return
 */

public static final Object getAsObject(byte[] bytes, ExternalContext ctx) {
    ByteArrayInputStream input = null;

    try {
        input = new ByteArrayInputStream(bytes);

        // get the Factory that was instantiated @ startup
        SerialFactory serialFactory = (SerialFactory) ctx.getApplicationMap().get(SERIAL_FACTORY);

        if (serialFactory == null)
            throw new NullPointerException("serialFactory");

        ObjectInputStream s = null;
        Exception pendingException = null;
        try {
            s = serialFactory.getObjectInputStream(input);
            Object object = null;
            if (System.getSecurityManager() != null) {
                final ObjectInputStream ois = s;
                object = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    //Put IOException and ClassNotFoundException as "checked" exceptions,
                    //so AccessController wrap them in a PrivilegedActionException
                    public Object run() throws PrivilegedActionException, IOException, ClassNotFoundException {
                        return ois.readObject();
                    }
                });
                // Since s has the same instance as ois,
                // we don't need to close it here, rather
                // close it on the finally block related to s
                // and avoid duplicate close exceptions
                // finally
                // {
                //    ois.close();
                // }
            } else {
                object = s.readObject();
            }
            return object;
        } catch (Exception e) {
            pendingException = e;
            throw new FacesException(e);
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (IOException e) {
                    // If a previous exception is thrown 
                    // ignore this, but if not, wrap it in a
                    // FacesException and throw it. In this way
                    // we preserve the original semantic of this
                    // method, but we handle correctly the case
                    // when we close a stream. Obviously, the 
                    // information about this exception is lost,
                    // but note that the interesting information 
                    // is always on pendingException, since we
                    // only do a readObject() on the outer try block.
                    if (pendingException == null) {
                        throw new FacesException(e);
                    }
                } finally {
                    s = null;
                }
            }
        }
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                //ignore it, because ByteArrayInputStream.close has
                //no effect, but it is better to call close and preserve
                //semantic from previous code.
            } finally {
                input = null;
            }
        }
    }
}

From source file:com.sshtools.j2ssh.forwarding.ForwardingClient.java

/**
 *
 *
 * @param fwd//  ww w.  j  a  va  2s  . c o  m
 *
 * @throws ForwardingConfigurationException
 */
public void addRemoteForwarding(ForwardingConfiguration fwd) throws ForwardingConfigurationException {
    // Check that the name does not exist
    if (remoteForwardings.containsKey(fwd.getName())) {
        throw new ForwardingConfigurationException("The remote forwaring configuration name already exists!");
    }

    // Check that the address to bind and port are not already being used
    Iterator it = remoteForwardings.values().iterator();
    ForwardingConfiguration config;

    while (it.hasNext()) {
        config = (ForwardingConfiguration) it.next();

        if (config.getAddressToBind().equals(fwd.getAddressToBind())
                && (config.getPortToBind() == fwd.getPortToBind())) {
            throw new ForwardingConfigurationException(
                    "The remote forwarding address and port are already in use");
        }
    }

    // Check the security mananger
    SecurityManager manager = System.getSecurityManager();

    if (manager != null) {
        try {
            manager.checkPermission(new SocketPermission(
                    fwd.getHostToConnect() + ":" + String.valueOf(fwd.getPortToConnect()), "connect"));
        } catch (SecurityException e) {
            throw new ForwardingConfigurationException("The security manager has denied connect permision on "
                    + fwd.getHostToConnect() + ":" + String.valueOf(fwd.getPortToConnect()));
        }
    }

    // Create the configuration object
    remoteForwardings.put(fwd.getName(), fwd);
}

From source file:org.apache.myfaces.shared.util.StateUtils.java

/**
 * Performs deserialization with the serialization provider created from the
 * SerialFactory./* www  .  ja  va  2 s . c om*/
 * 
 * @param bytes
 * @param ctx
 * @return
 */

public static final Object getAsObject(byte[] bytes, ExternalContext ctx) {
    ByteArrayInputStream input = null;

    try {
        input = new ByteArrayInputStream(bytes);

        // get the Factory that was instantiated @ startup
        SerialFactory serialFactory = (SerialFactory) ctx.getApplicationMap().get(SERIAL_FACTORY);

        if (serialFactory == null) {
            throw new NullPointerException("serialFactory");
        }

        ObjectInputStream s = null;
        Exception pendingException = null;
        try {
            s = serialFactory.getObjectInputStream(input);
            Object object = null;
            if (System.getSecurityManager() != null) {
                final ObjectInputStream ois = s;
                object = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                    //Put IOException and ClassNotFoundException as "checked" exceptions,
                    //so AccessController wrap them in a PrivilegedActionException
                    public Object run() throws PrivilegedActionException, IOException, ClassNotFoundException {
                        return ois.readObject();
                    }
                });
                // Since s has the same instance as ois,
                // we don't need to close it here, rather
                // close it on the finally block related to s
                // and avoid duplicate close exceptions
                // finally
                // {
                //    ois.close();
                // }
            } else {
                object = s.readObject();
            }
            return object;
        } catch (Exception e) {
            pendingException = e;
            throw new FacesException(e);
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (IOException e) {
                    // If a previous exception is thrown 
                    // ignore this, but if not, wrap it in a
                    // FacesException and throw it. In this way
                    // we preserve the original semantic of this
                    // method, but we handle correctly the case
                    // when we close a stream. Obviously, the 
                    // information about this exception is lost,
                    // but note that the interesting information 
                    // is always on pendingException, since we
                    // only do a readObject() on the outer try block.
                    if (pendingException == null) {
                        throw new FacesException(e);
                    }
                } finally {
                    s = null;
                }
            }
        }
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                //ignore it, because ByteArrayInputStream.close has
                //no effect, but it is better to call close and preserve
                //semantic from previous code.
            } finally {
                input = null;
            }
        }
    }
}

From source file:org.apache.catalina.core.ApplicationDispatcher.java

/**
 * Include the response from another resource in the current response.
 * Any runtime exception, IOException, or ServletException thrown by the
 * called servlet will be propogated to the caller.
 *
 * @param request The servlet request that is including this one
 * @param response The servlet response to be appended to
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 *//*ww  w  . j a v a2 s.c  o m*/
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    if (System.getSecurityManager() != null) {
        try {
            PrivilegedInclude dp = new PrivilegedInclude(request, response);
            AccessController.doPrivileged(dp);
        } catch (PrivilegedActionException pe) {
            Exception e = pe.getException();

            if (e instanceof ServletException)
                throw (ServletException) e;
            throw (IOException) e;
        }
    } else {
        doInclude(request, response);
    }
}