<commit_before>/*
 * FindBugs Eclipse Plug-in.
 * Copyright (C) 2003 - 2004, <NAME>
 * Copyright (C) 2005, University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package de.tobject.findbugs.reporter;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import de.tobject.findbugs.FindbugsPlugin;
import de.tobject.findbugs.marker.FindBugsMarker;
import de.tobject.findbugs.view.BugTreeView;
import edu.umd.cs.findbugs.AppVersion;
import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.Detector;
import edu.umd.cs.findbugs.Priorities;

/**
 * Creates a FindBugs marker in a runnable window.
 */
public class MarkerReporter implements IWorkspaceRunnable {
	BugInstance bug;
	IResource resource;
	int startLine;
	BugCollection collection;
	IProject project;

	public MarkerReporter(BugInstance bug, IResource resource, int startLine, BugCollection theCollection, IProject project) {
		this.startLine = startLine;
		this.bug=bug;
		this.resource=resource;
		this.collection=theCollection;
		this.project=project;
	}

    static final boolean EXPERIMENTAL_BUGS = false;
	public void run(IProgressMonitor monitor) throws CoreException {

		int priority = this.bug.getPriority();
        
		String markerName;
		switch(priority)
		{
			case Priorities.HIGH_PRIORITY:
				markerName = FindBugsMarker.NAME_HIGH;
				break;
			case Priorities.NORMAL_PRIORITY:
				markerName = FindBugsMarker.NAME_NORMAL;
				break;
			case Priorities.LOW_PRIORITY:
				markerName = FindBugsMarker.NAME_LOW;
				break;
			case Priorities.EXP_PRIORITY:
                if (!EXPERIMENTAL_BUGS) return;
				markerName = FindBugsMarker.NAME_EXPERIMENTAL;
				break;
			case Priorities.IGNORE_PRIORITY:
                FindbugsPlugin.getDefault().logError("Bug with ignore priority ");
                return;
			default:
				FindbugsPlugin.getDefault().logError("Bug with unknown priority " + priority);
			return;

		}
		IMarker marker = resource.createMarker(markerName);
		marker.setAttribute(IMarker.LINE_NUMBER, startLine);
		marker.setAttribute(FindBugsMarker.BUG_LINE_NUMBER, startLine);
		marker.setAttribute(FindBugsMarker.BUG_TYPE, bug.getType());
		AppVersion theVersion;
		long seqNum = bug.getFirstVersion();
		if(seqNum == 0)
			marker.setAttribute(FindBugsMarker.FIRST_VERSION, Long.toString(-1));
		else
		{
			theVersion = collection.getAppVersionFromSequenceNumber(seqNum);
			if(theVersion == null)
				marker.setAttribute(FindBugsMarker.FIRST_VERSION, "Cannot find AppVersion: seqnum=" + seqNum + "; collection seqnum=" + collection.getSequenceNumber());
			else
				marker.setAttribute(FindBugsMarker.FIRST_VERSION, Long.toString(theVersion.getTimestamp()));
		}
		marker.setAttribute(IMarker.MESSAGE, bug.getMessageWithPriorityTypeAbbreviation());
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
		marker.setAttribute(FindBugsMarker.PRIORITY_TYPE, bug.getPriorityTypeString());
		if (bug.getPriority() == Detector.HIGH_PRIORITY)
			marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
		else if (bug.getPriority() == Detector.NORMAL_PRIORITY)
			marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
		else marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);

		// Set unique id of warning, so we can easily refer back
		// to it later: for example, when the user classifies the warning.
		String uniqueId = bug.getInstanceHash();
		if (uniqueId != null) {
			marker.setAttribute(FindBugsMarker.UNIQUE_ID, uniqueId);
		}
		BugTreeView theView = BugTreeView.getBugTreeView();
		if(theView != null)
			theView.addMarker(project, marker);
	}
}<commit_msg>defensive coding<commit_after>/*
 * FindBugs Eclipse Plug-in.
 * Copyright (C) 2003 - 2004, <NAME>
 * Copyright (C) 2005, University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package de.tobject.findbugs.reporter;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import de.tobject.findbugs.FindbugsPlugin;
import de.tobject.findbugs.marker.FindBugsMarker;
import de.tobject.findbugs.view.BugTreeView;
import edu.umd.cs.findbugs.AppVersion;
import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.Detector;
import edu.umd.cs.findbugs.Priorities;

/**
 * Creates a FindBugs marker in a runnable window.
 */
public class MarkerReporter implements IWorkspaceRunnable {
	BugInstance bug;
	IResource resource;
	int startLine;
	BugCollection collection;
	IProject project;

	public MarkerReporter(BugInstance bug, IResource resource, int startLine, BugCollection theCollection, IProject project) {
		this.startLine = startLine;
		this.bug=bug;
		this.resource=resource;
		this.collection=theCollection;
		this.project=project;
	}

    static final boolean EXPERIMENTAL_BUGS = false;
	public void run(IProgressMonitor monitor) throws CoreException {

		int priority = this.bug.getPriority();
        
		String markerName;
		switch(priority)
		{
			case Priorities.HIGH_PRIORITY:
				markerName = FindBugsMarker.NAME_HIGH;
				break;
			case Priorities.NORMAL_PRIORITY:
				markerName = FindBugsMarker.NAME_NORMAL;
				break;
			case Priorities.LOW_PRIORITY:
				markerName = FindBugsMarker.NAME_LOW;
				break;
			case Priorities.EXP_PRIORITY:
                if (!EXPERIMENTAL_BUGS) return;
				markerName = FindBugsMarker.NAME_EXPERIMENTAL;
				break;
			case Priorities.IGNORE_PRIORITY:
                FindbugsPlugin.getDefault().logError("Bug with ignore priority ");
                return;
			default:
				FindbugsPlugin.getDefault().logError("Bug with unknown priority " + priority);
			return;

		}
		IMarker marker = resource.createMarker(markerName);
		marker.setAttribute(IMarker.LINE_NUMBER, startLine);
		marker.setAttribute(FindBugsMarker.BUG_LINE_NUMBER, startLine);
		marker.setAttribute(FindBugsMarker.BUG_TYPE, bug.getType());
		AppVersion theVersion;
		long seqNum = bug.getFirstVersion();
		if(seqNum == 0)
			marker.setAttribute(FindBugsMarker.FIRST_VERSION, Long.toString(-1));
		else
		{
			theVersion = collection.getAppVersionFromSequenceNumber(seqNum);
			if(theVersion == null)
				marker.setAttribute(FindBugsMarker.FIRST_VERSION, "Cannot find AppVersion: seqnum=" + seqNum + "; collection seqnum=" + collection.getSequenceNumber());
			else
				marker.setAttribute(FindBugsMarker.FIRST_VERSION, Long.toString(theVersion.getTimestamp()));
		}
        try {
		marker.setAttribute(IMarker.MESSAGE, bug.getMessageWithPriorityTypeAbbreviation());
        } catch (RuntimeException e) {
            FindbugsPlugin.getDefault().logException(e, "Error generating msg for " + bug.getType());
            marker.setAttribute(IMarker.MESSAGE, "??? " + bug.getType());
        }
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
		marker.setAttribute(FindBugsMarker.PRIORITY_TYPE, bug.getPriorityTypeString());
		if (bug.getPriority() == Detector.HIGH_PRIORITY)
			marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
		else if (bug.getPriority() == Detector.NORMAL_PRIORITY)
			marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
		else marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);

		// Set unique id of warning, so we can easily refer back
		// to it later: for example, when the user classifies the warning.
		String uniqueId = bug.getInstanceHash();
		if (uniqueId != null) {
			marker.setAttribute(FindBugsMarker.UNIQUE_ID, uniqueId);
		}
		BugTreeView theView = BugTreeView.getBugTreeView();
		if(theView != null)
			theView.addMarker(project, marker);
	}
}
{'fraction_non_alphanumeric': 0.09402889927751806, 'fraction_numerical': 0.006374840628984276, 'mean_word_length': 4.566528681253696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4740488', 'n_tokens_mistral': 3120, 'n_tokens_neox': 2825, 'n_words': 709}