google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Getting OOM instead of FormatterException

Open jayendra13 opened this issue 5 years ago • 0 comments

For the following example I am getting OOM error instead of FormatterException.

/*package org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.parts;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;
import org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.policies.ProxyServiceSequenceContainerCanonicalEditPolicy;
import org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.policies.ProxyServiceSequenceContainerItemSemanticEditPolicy;

*//**
 * @generated
 *//*
public class ProxyServiceSequenceContainerEditPart extends ShapeNodeEditPart {

	*//**
	 * @generated
	 *//*
	public static final int VISUAL_ID = 3391;

	*//**
	 * @generated
	 *//*
	protected IFigure contentPane;

	*//**
	 * @generated
	 *//*
	protected IFigure primaryShape;

	*//**
	 * @generated
	 *//*
	public ProxyServiceSequenceContainerEditPart(View view) {
		super(view);
	}

	*//**
	 * @generated
	 *//*
	protected void createDefaultEditPolicies() {
		installEditPolicy(EditPolicyRoles.CREATION_ROLE,
				new CreationEditPolicy());
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new ProxyServiceSequenceContainerItemSemanticEditPolicy());
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
				new DragDropEditPolicy());
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
				new ProxyServiceSequenceContainerCanonicalEditPolicy());
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
	}

	*//**
	 * @generated
	 *//*
	protected LayoutEditPolicy createLayoutEditPolicy() {
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {

			protected EditPolicy createChildEditPolicy(EditPart child) {
				EditPolicy result = child
						.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
				if (result == null) {
					result = new NonResizableEditPolicy();
				}
				return result;
			}

			protected Command getMoveChildrenCommand(Request request) {
				return null;
			}

			protected Command getCreateCommand(CreateRequest request) {
				return null;
			}
		};
		return lep;
	}

	*//**
	 * @generated
	 *//*
	protected IFigure createNodeShape() {
		return primaryShape = new ProxyServiceSequenceContainerFigure();
	}

	*//**
	 * @generated
	 *//*
	public ProxyServiceSequenceContainerFigure getPrimaryShape() {
		return (ProxyServiceSequenceContainerFigure) primaryShape;
	}

	*//**
	 * @generated
	 *//*
	protected NodeFigure createNodePlate() {
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40);
		return result;
	}

	*//**
	 * Creates figure for this edit part.
	 *
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 *
	 * @generated
	 *//*
	protected NodeFigure createNodeFigure() {
		NodeFigure figure = createNodePlate();
		figure.setLayoutManager(new StackLayout());
		IFigure shape = createNodeShape();
		figure.add(shape);
		contentPane = setupContentPane(shape);
		return figure;
	}

	*//**
	 * Default implementation treats passed figure as content pane.
	 * Respects layout one may have set for generated figure.
	 * @param nodeShape instance of generated figure class
	 * @generated
	 *//*
	protected IFigure setupContentPane(IFigure nodeShape) {
		if (nodeShape.getLayoutManager() == null) {
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
			layout.setSpacing(5);
			nodeShape.setLayoutManager(layout);
		}
		return nodeShape; // use nodeShape itself as contentPane
	}

	*//**
	 * @generated
	 *//*
	public IFigure getContentPane() {
		if (contentPane != null) {
			return contentPane;
		}
		return super.getContentPane();
	}

	*//**
	 * @generated
	 *//*
	protected void setForegroundColor(Color color) {
		if (primaryShape != null) {
			primaryShape.setForegroundColor(color);
		}
	}

	*//**
	 * @generated
	 *//*
	protected void setBackgroundColor(Color color) {
		if (primaryShape != null) {
			primaryShape.setBackgroundColor(color);
		}
	}

	*//**
	 * @generated
	 *//*
	protected void setLineWidth(int width) {
		if (primaryShape instanceof Shape) {
			((Shape) primaryShape).setLineWidth(width);
		}
	}

	*//**
	 * @generated
	 *//*
	protected void setLineType(int style) {
		if (primaryShape instanceof Shape) {
			((Shape) primaryShape).setLineStyle(style);
		}
	}

	*//**
	 * @generated
	 *//*
	public class ProxyServiceSequenceContainerFigure extends RoundedRectangle {

		*//**
		 * @generated NOT
		 *//*
		public ProxyServiceSequenceContainerFigure() {

					GridLayout layoutThis = new GridLayout();
					layoutThis.numColumns = 1;
					layoutThis.makeColumnsEqualWidth = true;
					this.setLayoutManager(layoutThis);

			ToolbarLayout layoutThis = new ToolbarLayout();
			layoutThis.setStretchMinorAxis(true);
			layoutThis.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
			layoutThis.setSpacing(0);
			layoutThis.setVertical(true);

			this.setLayoutManager(layoutThis);

			this.setCornerDimensions(new Dimension(getMapMode().DPtoLP(8),
					getMapMode().DPtoLP(8)));
			this.setLineStyle(Graphics.LINE_DASH);
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(3000),
					getMapMode().DPtoLP(500)));
			this.setOutline(false);

			this.setBackgroundColor(THIS_BACK);
		}

		protected void fillShape(Graphics graphics) {
			// Backup the graphics colors
			Color bgColor = graphics.getBackgroundColor();
			Color fgColor = graphics.getForegroundColor();
			// Set the graphics color
			graphics.setBackgroundColor(getBackgroundColor());
			graphics.setForegroundColor(ColorConstants.white);
			// Restore the original colors
			graphics.fillGradient(getBounds(), true);
			graphics.setBackgroundColor(bgColor);
			graphics.setForegroundColor(fgColor);
		}

	}

	public boolean isSelectable() {
		// TODO This or using ResizableEditpolicy?
		return false;
	}

	*//**
	 * @generated
	 *//*
	static final Color THIS_BACK = new Color(null, 255, 255, 255);

}
*/

When I pass the example stated above to the Formatter I am getting the OOM, which I shouldn't expect. The driver code I am using is

package com.foo;

import com.google.googlejavaformat.java.Formatter;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Playground {
    public static String readCode() throws Exception{
        return new String(Files.readAllBytes(Paths.get("example")));
    }

    public static void main(String[] args) throws Exception{

        String code = readCode();
        System.out.println(code);

        Formatter formatter = new Formatter();
        String out = formatter.formatSource(code);
        System.out.println(out);
    }
}

jayendra13 avatar Mar 13 '20 08:03 jayendra13