<commit_before>package edu.columbia.cs.psl.phosphor;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;

import com.sun.xml.internal.ws.org.objectweb.asm.Type;

import edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.AnnotationVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassReader;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassWriter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.MethodVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.Opcodes;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.commons.JSRInlinerAdapter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.commons.SerialVersionUIDAdder;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.util.CheckClassAdapter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.util.TraceClassVisitor;
import edu.columbia.cs.psl.phosphor.runtime.TaintInstrumented;
import edu.columbia.cs.psl.phosphor.struct.TaintedByteArray;

public class PreMain {
    private static Instrumentation instrumentation;

    static boolean DEBUG = false;

	public static ClassLoader bigLoader = PreMain.class.getClassLoader();
	public static final class PCLoggingTransformer implements ClassFileTransformer {
		private final class HackyClassWriter extends ClassWriter {
			
			private HackyClassWriter(ClassReader classReader, int flags) {
				super(classReader, flags);
			}

			private Class<?> getClass(String name) throws ClassNotFoundException
			{
				try {
					return Class.forName(name.replace("/", "."),false,bigLoader);
				} catch (SecurityException e) {
					throw new ClassNotFoundException("Security exception when loading class");
				} catch(NoClassDefFoundError e)
				{
					throw new ClassNotFoundException();
				}
				catch(Throwable e)
				{
					throw new ClassNotFoundException(); 
				}
			}
			protected String getCommonSuperClass(String type1, String type2) {
				Class<?> c, d;
				try {
					c = getClass(type1);
					d = getClass(type2);
				} catch (ClassNotFoundException e) {
//					System.err.println("Can not do superclass for " + type1 + " and " + type2);
					//					        	logger.debug("Error while finding common super class for " + type1 +"; " + type2,e);
					return "java/lang/Object";
					//					        	throw new RuntimeException(e);
				} catch (ClassCircularityError e) {
					return "java/lang/Object";
				}
				if (c.isAssignableFrom(d)) {
					return type1;
				}
				if (d.isAssignableFrom(c)) {
					return type2;
				}
				if (c.isInterface() || d.isInterface()) {
					return "java/lang/Object";
				} else {
					do {
						c = c.getSuperclass();
					} while (!c.isAssignableFrom(d));
//					System.out.println("Returning " + c.getName());
					return c.getName().replace('.', '/');
				}
			}
		}
		private void upgradeToForceFrames(ClassReader cr, ClassWriter cw) throws Throwable
		{
//			System.out.println("upgrading: " + cr.getClassName());
			ClassWriter cw2 = new HackyClassWriter(cr,ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
			cr.accept(new ClassVisitor(Opcodes.ASM5,cw2) {
				@Override
				public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
//					System.out.println("old was " + version);
					version = 50;
					if((access & Opcodes.ACC_INTERFACE) != 0)
						access |= Opcodes.ACC_ABSTRACT;
					super.visit(version, access, name, signature, superName, interfaces);
				}
				@Override
				public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
					return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions);
				}
			}, ClassReader.EXPAND_FRAMES);
			byte[] newClass = cw2.toByteArray();
			cr = new ClassReader(newClass);

			try{
			cr.accept(
//					new CheckClassAdapter(
							new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cw))
//							)
					, ClassReader.EXPAND_FRAMES);
			}
			catch(Throwable ex)
			{
				PrintWriter pw = null;<commit_msg>Clear the ACC_SUPER flag when upgrading from JDK 1.1<commit_after>package edu.columbia.cs.psl.phosphor;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;

import com.sun.xml.internal.ws.org.objectweb.asm.Type;

import edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.AnnotationVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassReader;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.ClassWriter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.MethodVisitor;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.Opcodes;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.commons.JSRInlinerAdapter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.commons.SerialVersionUIDAdder;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.util.CheckClassAdapter;
import edu.columbia.cs.psl.phosphor.org.objectweb.asm.util.TraceClassVisitor;
import edu.columbia.cs.psl.phosphor.runtime.TaintInstrumented;
import edu.columbia.cs.psl.phosphor.struct.TaintedByteArray;

public class PreMain {
    private static Instrumentation instrumentation;

    static boolean DEBUG = true;

	public static ClassLoader bigLoader = PreMain.class.getClassLoader();
	public static final class PCLoggingTransformer implements ClassFileTransformer {
		private final class HackyClassWriter extends ClassWriter {
			
			private HackyClassWriter(ClassReader classReader, int flags) {
				super(classReader, flags);
			}

			private Class<?> getClass(String name) throws ClassNotFoundException
			{
				try {
					return Class.forName(name.replace("/", "."),false,bigLoader);
				} catch (SecurityException e) {
					throw new ClassNotFoundException("Security exception when loading class");
				} catch(NoClassDefFoundError e)
				{
					throw new ClassNotFoundException();
				}
				catch(Throwable e)
				{
					throw new ClassNotFoundException(); 
				}
			}
			protected String getCommonSuperClass(String type1, String type2) {
				Class<?> c, d;
				try {
					c = getClass(type1);
					d = getClass(type2);
				} catch (ClassNotFoundException e) {
//					System.err.println("Can not do superclass for " + type1 + " and " + type2);
					//					        	logger.debug("Error while finding common super class for " + type1 +"; " + type2,e);
					return "java/lang/Object";
					//					        	throw new RuntimeException(e);
				} catch (ClassCircularityError e) {
					return "java/lang/Object";
				}
				if (c.isAssignableFrom(d)) {
					return type1;
				}
				if (d.isAssignableFrom(c)) {
					return type2;
				}
				if (c.isInterface() || d.isInterface()) {
					return "java/lang/Object";
				} else {
					do {
						c = c.getSuperclass();
					} while (!c.isAssignableFrom(d));
//					System.out.println("Returning " + c.getName());
					return c.getName().replace('.', '/');
				}
			}
		}
		private void upgradeToForceFrames(ClassReader cr, ClassWriter cw) throws Throwable
		{
//			System.out.println("upgrading: " + cr.getClassName());
			ClassWriter cw2 = new HackyClassWriter(cr,ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
			cr.accept(new ClassVisitor(Opcodes.ASM5,cw2) {
				@Override
				public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
//					System.out.println("old was " + version);
					version = 50;
					access = access & ~Opcodes.ACC_SUPER;

					if((access & Opcodes.ACC_INTERFACE) != 0)
						access |= Opcodes.ACC_ABSTRACT;
					super.visit(version, access, name, signature, superName, interfaces);
				}
				@Override
				public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
					return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions);
				}
			}, ClassReader.EXPAND_FRAMES);
			byte[] newClass = cw2.toByteArray();
			cr = new ClassReader(newClass);

			try{
			cr.accept(
//					new CheckClassAdapter(
							new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cw))
//							)
					, ClassReader.EXPAND_FRAMES);
			}
			catch(Throwable ex)
			{
				PrintWriter pw = null;
{'fraction_non_alphanumeric': 0.11652636242800177, 'fraction_numerical': 0.003987594151528578, 'mean_word_length': 3.8335117773019274, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7387323', 'n_tokens_mistral': 3467, 'n_tokens_neox': 2899, 'n_words': 558}