Search in sources :

Example 6 with EmptyStackException

use of java.util.EmptyStackException in project poi by apache.

the class TestMissingArgEval method testEvaluateMissingArgs.

public void testEvaluateMissingArgs() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFCell cell = sheet.createRow(0).createCell(0);
    cell.setCellFormula("if(true,)");
    fe.clearAllCachedResultValues();
    CellValue cv;
    try {
        cv = fe.evaluate(cell);
    } catch (EmptyStackException e) {
        throw new AssertionFailedError("Missing args evaluation not implemented (bug 43354");
    }
    // MissingArg -> BlankEval -> zero (as formula result)
    assertEquals(0.0, cv.getNumberValue(), 0.0);
    // MissingArg -> BlankEval -> empty string (in concatenation)
    cell.setCellFormula("\"abc\"&if(true,)");
    fe.clearAllCachedResultValues();
    assertEquals("abc", fe.evaluate(cell).getStringValue());
}
Also used : HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) EmptyStackException(java.util.EmptyStackException) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 7 with EmptyStackException

use of java.util.EmptyStackException in project robovm by robovm.

the class NamespaceSupportTest method testPush_PopContext.

public void testPush_PopContext() {
    int count;
    ns = new NamespaceSupport();
    count = countPrefixes();
    ns.pushContext();
    ns.declarePrefix("dc", "http://www.purl.org/dc#");
    assertEquals("Test 1: Incorrect prefix count;", count + 1, countPrefixes());
    ns.popContext();
    assertEquals("Test 2: Incorrect prefix count;", count, countPrefixes());
    // Check that only one context has been created by pushContext().
    try {
        ns.popContext();
        fail("Test 3: EmptyStackException expected.");
    } catch (EmptyStackException e) {
    // Expected.
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 8 with EmptyStackException

use of java.util.EmptyStackException in project Algorithms by wlsgussla123.

the class Main method pop.

public T pop() {
    if (isEmpty())
        throw new EmptyStackException();
    StackNode del = top;
    T data = del.data;
    top = top.next;
    return data;
}
Also used : EmptyStackException(java.util.EmptyStackException)

Example 9 with EmptyStackException

use of java.util.EmptyStackException in project cytoscape-impl by cytoscape.

the class InterpreterImpl method call.

private void call() throws EmptyStackException, IllegalStateException, FunctionError {
    // 1. get the function
    final Object o = argumentStack.pop();
    if (!(o instanceof Function))
        throw new IllegalStateException("expected a column function after the CALL opcode but found \"" + o.getClass() + "\" instead.");
    final Function func = (Function) o;
    // 2. get and validate the argument count
    final int argCount;
    try {
        argCount = (Integer) argumentStack.pop();
    } catch (final Exception e) {
        throw new IllegalStateException("invalid argument count type following a CALL opcode.");
    }
    final int MIN_ARG_COUNT = 0;
    // This is an arbitrary limit and exists only to find bugs.
    final int MAX_ARG_COUNT = 100;
    // Should it prove to be too low we could easily make it much bigger.
    if (argCount < MIN_ARG_COUNT || argCount > MAX_ARG_COUNT)
        throw new IllegalStateException("invalid argument count type following a CALL opcode (range must be in [" + MIN_ARG_COUNT + ", " + MAX_ARG_COUNT + "]).");
    // 3. collect the actual arguments
    final Object[] args = new Object[argCount];
    for (int argNo = 0; argNo < argCount; ++argNo) args[argNo] = argumentStack.pop();
    // 4. now actually call the function
    argumentStack.push(func.evaluateFunction(args));
}
Also used : Function(org.cytoscape.equations.Function) EmptyStackException(java.util.EmptyStackException)

Example 10 with EmptyStackException

use of java.util.EmptyStackException in project jsql-injection by ron190.

the class CreateAdminPageTab method execute.

@Override
public void execute() {
    if (MediatorGui.tabResults() == null) {
        LOGGER.error("Unexpected unregistered MediatorGui.tabResults() in " + this.getClass());
    }
    String htmlSource = "";
    // Fix #44641: ExceptionInInitializerError on get()
    try {
        // Previous test for 2xx Success and 3xx Redirection was Header only,
        // now get the HTML content.
        // Proxy is used by jsoup
        htmlSource = Jsoup.clean(Jsoup.connect(this.url).get().html().replaceAll("<img.*>", "").replaceAll("<input.*type=\"?hidden\"?.*>", "").replaceAll("<input.*type=\"?(submit|button)\"?.*>", "<div style=\"background-color:#eeeeee;text-align:center;border:1px solid black;width:100px;\">button</div>").replaceAll("<input.*>", "<div style=\"text-align:center;border:1px solid black;width:100px;\">input</div>"), Whitelist.relaxed().addTags("center", "div", "span").addAttributes(":all", "style"));
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (ExceptionInInitializerError | NoClassDefFoundError e) {
        LOGGER.warn("Jsoup not properly configured, please update jsql", e);
    }
    final JTextPane browser = new JTextPane();
    browser.setContentType("text/html");
    browser.setEditable(false);
    // Fix #43220: EmptyStackException on setText()
    try {
        browser.setText(htmlSource);
    } catch (EmptyStackException e) {
        LOGGER.error(e, e);
    }
    final JPopupMenu menu = new JPopupMenu();
    JMenuItem itemCopyUrl = new JMenuItem(I18n.valueByKey("CONTEXT_MENU_COPY_PAGE_URL"));
    I18nView.addComponentForKey("CONTEXT_MENU_COPY_PAGE_URL", itemCopyUrl);
    itemCopyUrl.setIcon(HelperUi.ICON_EMPTY);
    JMenuItem itemCopy = new JMenuItem();
    itemCopy.setAction(browser.getActionMap().get(DefaultEditorKit.copyAction));
    itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    itemCopy.setMnemonic('C');
    itemCopy.setText(I18n.valueByKey("CONTEXT_MENU_COPY"));
    I18nView.addComponentForKey("CONTEXT_MENU_COPY", itemCopy);
    itemCopy.setIcon(HelperUi.ICON_EMPTY);
    JMenuItem itemSelectAll = new JMenuItem();
    itemSelectAll.setIcon(HelperUi.ICON_EMPTY);
    itemSelectAll.setAction(browser.getActionMap().get(DefaultEditorKit.selectAllAction));
    itemSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    itemSelectAll.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL"));
    I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", itemSelectAll);
    itemSelectAll.setMnemonic('A');
    menu.add(itemCopyUrl);
    menu.add(new JSeparator());
    menu.add(itemCopy);
    menu.add(itemSelectAll);
    menu.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()));
    itemCopyUrl.addActionListener(actionEvent -> {
        StringSelection stringSelection = new StringSelection(CreateAdminPageTab.this.url);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
    });
    itemSelectAll.addActionListener(actionEvent -> browser.selectAll());
    browser.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent arg0) {
            browser.getCaret().setVisible(true);
            browser.getCaret().setSelectionVisible(true);
        }
    });
    browser.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent evt) {
            browser.requestFocusInWindow();
            if (evt.isPopupTrigger()) {
                menu.show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                // Fix #45348: IllegalComponentStateException on show()
                try {
                    menu.show(evt.getComponent(), evt.getX(), evt.getY());
                } catch (IllegalComponentStateException e) {
                    LOGGER.error(e, e);
                }
                menu.setLocation(ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? evt.getXOnScreen() - menu.getWidth() : evt.getXOnScreen(), evt.getYOnScreen());
            }
        }
    });
    final LightScrollPane scroller = new LightScrollPane(1, 0, 0, 0, browser);
    MediatorGui.tabResults().addTab(this.url.replaceAll(".*/", "") + " ", scroller);
    // Focus on the new tab
    MediatorGui.tabResults().setSelectedComponent(scroller);
    // Create a custom tab header with close button
    TabHeader header = new TabHeader(this.url.replaceAll(".*/", ""), HelperUi.ICON_ADMIN_SERVER);
    MediatorGui.tabResults().setToolTipTextAt(MediatorGui.tabResults().indexOfComponent(scroller), "<html>" + this.url + "</html>");
    // Apply the custom header to the tab
    MediatorGui.tabResults().setTabComponentAt(MediatorGui.tabResults().indexOfComponent(scroller), header);
    // Give focus to the admin page
    browser.requestFocusInWindow();
    // Get back to the top
    SwingUtilities.invokeLater(() -> scroller.scrollPane.getViewport().setViewPosition(new java.awt.Point(0, 0)));
}
Also used : TabHeader(com.jsql.view.swing.tab.TabHeader) FocusAdapter(java.awt.event.FocusAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) LightScrollPane(com.jsql.view.swing.scrollpane.LightScrollPane) IOException(java.io.IOException) FocusEvent(java.awt.event.FocusEvent) IllegalComponentStateException(java.awt.IllegalComponentStateException) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) StringSelection(java.awt.datatransfer.StringSelection) EmptyStackException(java.util.EmptyStackException) JTextPane(javax.swing.JTextPane) Clipboard(java.awt.datatransfer.Clipboard) JMenuItem(javax.swing.JMenuItem)

Aggregations

EmptyStackException (java.util.EmptyStackException)47 Stack (java.util.Stack)13 Test (org.junit.Test)6 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)5 Callable (java.util.concurrent.Callable)5 NamespaceSupport (org.xml.sax.helpers.NamespaceSupport)5 ActivityImple (com.arjuna.mwlabs.wsas.activity.ActivityImple)3 IOException (java.io.IOException)3 ResourceApplicationContext (com.cloud.spring.module.context.ResourceApplicationContext)2 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)2 ArrayList (java.util.ArrayList)2 SystemException (org.omg.CORBA.SystemException)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ActionControl (com.arjuna.ArjunaOTS.ActionControl)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 LightScrollPane (com.jsql.view.swing.scrollpane.LightScrollPane)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 FileOptions (com.laytonsmith.core.compiler.FileOptions)1 KeywordList (com.laytonsmith.core.compiler.KeywordList)1 CDecimal (com.laytonsmith.core.constructs.CDecimal)1