下面列出了java.lang.reflect.MalformedParametersException#java.lang.Class 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getDeclaredField(field1);
Field f2 = klass.getDeclaredField(field2);
if (isStatic(f1) != isStatic(f2)) {
return true; // these guys are in naturally disjoint locations
}
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getDeclaredField(field1);
Field f2 = klass.getDeclaredField(field2);
if (isStatic(f1) != isStatic(f2)) {
return true; // these guys are in naturally disjoint locations
}
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
private static int estimateBaseFromCatalog( Class cls, boolean addToCatalog)
{
if( dummyCatalog)
return 0;
if( SanityManager.DEBUG)
SanityManager.ASSERT( catalog != null, "The class size catalog could not be initialized.");
int[] coeff = (int[]) catalog.get( cls.getName());
if( coeff == null)
{
try
{
coeff = getSizeCoefficients( cls);
}
catch( Throwable t)
{
if( noGuess)
return -2;
coeff = wildGuess;
}
if( addToCatalog)
catalog.put( cls.getName(), coeff);
}
return estimateBaseFromCoefficients( coeff);
}
public static Object instantiateXMLService(String serviceName) throws Exception {
ClassLoader backup = Thread.currentThread().getContextClassLoader();
try {
// set thread context class loader to module class loader
Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
if (serviceName.equals("org.xml.sax.XMLReader"))
return XMLReaderFactory.createXMLReader();
else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
return Class.forName(serviceName).getMethod("newInstance", String.class)
.invoke(null, W3C_XML_SCHEMA_NS_URI);
else
return Class.forName(serviceName).getMethod("newInstance").invoke(null);
} finally {
Thread.currentThread().setContextClassLoader(backup);
}
}
private Class<?> findJsonEquivalent( String scalarName )
{
switch( scalarName )
{
case "Time":
case "LocalTime":
return findFormatType( "time" );
case "Date":
case "LocalDate":
return findFormatType( "date" );
case "DateTime":
case "LocalDateTime":
return findFormatType( "date-time" );
case "Instant":
return findFormatType( "utc-millisec" );
case "Base64":
return findFormatType( "binary" );
case "Binary":
case "Octet":
return findFormatType( "byte" );
}
return String.class;
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getDeclaredField(field1);
Field f2 = klass.getDeclaredField(field2);
if (isStatic(f1) != isStatic(f2)) {
return true; // these guys are in naturally disjoint locations
}
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getDeclaredField(field1);
Field f2 = klass.getDeclaredField(field2);
if (isStatic(f1) != isStatic(f2)) {
return true; // these guys are in naturally disjoint locations
}
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
public static void main(String[] args) {
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:SquirrelAI.db");
statement = connection.createStatement();
// String sql = "CREATE TABLE message(date varchar(255),name varchar(255),message varchar(512));";
//UserName、NickName、RemarkName、Province、City
String sql = "CREATE TABLE user(username varchar(255),nickname varchar(255),remarkname varchar(512),province varchar(512),city varchar(512));";
statement.executeUpdate(sql);
statement.close();
connection.close();
System.out.println("数据库创建成功!");
} catch (Exception e) {
e.printStackTrace();
}
}
private void addInnerInterfaceType( InterfaceTypeDefinition type, SrcLinkedClass enclosingType )
{
String identifier = makeIdentifier( type.getName(), false );
String fqn = getFqn() + '.' + identifier;
SrcLinkedClass srcClass = new SrcLinkedClass( fqn, enclosingType, Interface )
.addInterface( IJsonBindingsBacked.class.getSimpleName() )
.addAnnotation( new SrcAnnotationExpression( Structural.class.getSimpleName() )
.addArgument( "factoryClass", Class.class, identifier + ".ProxyFactory.class" ) )
.modifiers( Modifier.PUBLIC );
addUnionInterfaces( type, srcClass );
addActualNameAnnotation( srcClass, type.getName(), false );
addSourcePositionAnnotation( srcClass, type, srcClass );
addProxyFactory( srcClass );
List<FieldDefinition> fieldDefinitions = type.getFieldDefinitions();
for( FieldDefinition member: fieldDefinitions )
{
addMember( srcClass, member, name -> fieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) );
}
addInterfaceExtensions( type, srcClass );
enclosingType.addInnerClass( srcClass );
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getField(field1);
Field f2 = klass.getField(field2);
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {
try {
System.err.println("Trying " + cls);
final Method method = cls.getMethod("m", int.class, int.class);
final Parameter[] params = method.getParameters();
System.err.println("Name " + params[0].getName());
System.err.println("Did not see expected exception");
errors++;
} catch(MalformedParametersException e) {
System.err.println("Expected exception seen");
}
}
public void run() throws NoSuchMethodException {
for (Class<?> cls : classes)
assertBadParameters(cls);
if (errors != 0)
throw new RuntimeException(errors + " errors in test");
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getField(field1);
Field f2 = klass.getField(field2);
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getField(field1);
Field f2 = klass.getField(field2);
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getField(field1);
Field f2 = klass.getField(field2);
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
private SrcType makeSrcType( SrcLinkedClass owner, Type type, boolean typeParam )
{
SrcType srcType;
if( type instanceof ListType )
{
srcType = new SrcType( "List" );
srcType.addTypeParam( makeSrcType( owner, ((ListType)type).getType(), true ) );
}
else if( type instanceof TypeName )
{
String typeName = getJavaClassName( owner, (TypeName)type, typeParam );
srcType = new SrcType( typeName );
if( !typeParam )
{
Class<?> javaClass = getJavaClass( (TypeName)type, false );
srcType.setPrimitive( javaClass != null && javaClass.isPrimitive() );
}
}
else if( type instanceof NonNullType )
{
Type theType = ((NonNullType)type).getType();
srcType = makeSrcType( owner, theType, typeParam );
if( !typeParam && !srcType.isPrimitive() )
{
srcType.addAnnotation( new SrcAnnotationExpression( NotNull.class.getSimpleName() ) );
}
}
else
{
throw new IllegalStateException( "Unhandled type: " + type.getClass().getTypeName() );
}
return srcType;
}
public static boolean arePaddedPairwise(Class klass, String field1, String field2) throws Exception {
Field f1 = klass.getField(field1);
Field f2 = klass.getField(field2);
int diff = offset(f1) - offset(f2);
if (diff < 0) {
// f1 is first
return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else {
// f2 is first
return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
public static int getSize(Field field) {
Class type = field.getType();
if (type == byte.class) { return 1; }
if (type == boolean.class) { return 1; }
if (type == short.class) { return 2; }
if (type == char.class) { return 2; }
if (type == int.class) { return 4; }
if (type == float.class) { return 4; }
if (type == long.class) { return 8; }
if (type == double.class) { return 8; }
return ADDRESS_SIZE;
}
public Tester makeAnon(final String message) {
return new Tester(2) {
protected String[] names() {
return new String[] {
"this$1",
"param",
"val$message"
};
}
protected int[] modifiers() {
return new int[] {
Modifier.FINAL | MANDATED,
Modifier.FINAL,
Modifier.FINAL | SYNTHETIC
};
}
protected Class[] types() {
return new Class[] {
Encloser.class,
int.class,
String.class
};
}
public String message() {
return message;
}
};
}
public Tester makeAnonExtendsInner(final String message) {
return new InnerTester(2) {
protected String[] names() {
return new String[] {
"this$1",
"innerparam",
"val$message"
};
}
protected int[] modifiers() {
return new int[] {
Modifier.FINAL | MANDATED,
Modifier.FINAL,
Modifier.FINAL | SYNTHETIC
};
}
protected Class[] types() {
return new Class[] {
Encloser.class,
int.class,
String.class
};
}
public String message() {
return message;
}
};
}
public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {
try {
System.err.println("Trying " + cls);
final Method method = cls.getMethod("m", int.class, int.class);
final Parameter[] params = method.getParameters();
System.err.println("Name " + params[0].getName());
System.err.println("Did not see expected exception");
errors++;
} catch(MalformedParametersException e) {
System.err.println("Expected exception seen");
}
}
public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {
try {
System.err.println("Trying " + cls);
final Method method = cls.getMethod("m", int.class, int.class);
final Parameter[] params = method.getParameters();
System.err.println("Name " + params[0].getName());
System.err.println("Did not see expected exception");
errors++;
} catch(MalformedParametersException e) {
System.err.println("Expected exception seen");
}
}
public Tester makeAnonExtendsLocal(final String message) {
abstract class LocalTester extends Tester {
public LocalTester(final int localparam) {
super(localparam);
}
protected String[] names() {
return new String[] {
"this$1",
"localparam",
"val$message"
};
}
protected int[] modifiers() {
return new int[] {
Modifier.FINAL | MANDATED,
Modifier.FINAL,
Modifier.FINAL | SYNTHETIC
};
}
protected Class[] types() {
return new Class[] {
Encloser.class,
int.class,
String.class
};
}
}
return new LocalTester(2) {
public String message() {
return message;
}
};
}
public Tester makeLocal(final String message) {
class LocalTester extends Tester {
public LocalTester(final int localparam) {
super(localparam);
}
protected String[] names() {
return new String[] {
"this$1",
"localparam",
"val$message"
};
}
protected int[] modifiers() {
return new int[] {
Modifier.FINAL | MANDATED,
Modifier.FINAL,
Modifier.FINAL | SYNTHETIC
};
}
protected Class[] types() {
return new Class[] {
Encloser.class,
int.class,
String.class
};
}
public String message() {
return message;
}
}
return new LocalTester(2);
}
static SystemException getSystemException(
String exClassName, int minorCode, CompletionStatus completionStatus,
String message, ORBUtilSystemException wrapper)
{
SystemException sysEx = null;
try {
Class<?> clazz =
SharedSecrets.getJavaCorbaAccess().loadClass(exClassName);
if (message == null) {
sysEx = (SystemException) clazz.newInstance();
} else {
Class[] types = { String.class };
Constructor constructor = clazz.getConstructor(types);
Object[] args = { message };
sysEx = (SystemException)constructor.newInstance(args);
}
} catch (Exception someEx) {
throw wrapper.badSystemExceptionInReply(
CompletionStatus.COMPLETED_MAYBE, someEx );
}
sysEx.minor = minorCode;
sysEx.completed = completionStatus;
return sysEx;
}