Java Code Examples for org.apache.bcel.Const#ACC_SYNCHRONIZED
The following examples show how to use
org.apache.bcel.Const#ACC_SYNCHRONIZED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindUnsyncGet.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visit(Method obj) { int flags = obj.getAccessFlags(); if ((flags & doNotConsider) != 0) { return; } String name = obj.getName(); boolean isSynchronized = (flags & Const.ACC_SYNCHRONIZED) != 0; /* * String sig = obj.getSignature(); char firstArg = sig.charAt(1); char * returnValue = sig.charAt(1 + sig.indexOf(')')); boolean firstArgIsRef * = (firstArg == 'L') || (firstArg == '['); boolean returnValueIsRef = * (returnValue == 'L') || (returnValue == '['); * * System.out.println(className + "." + name + " " + firstArgIsRef + " " * + returnValueIsRef + " " + isSynchronized + " " + isNative ); */ if (name.startsWith("get") && !isSynchronized // && returnValueIsRef ) { getMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } else if (name.startsWith("set") && isSynchronized // && firstArgIsRef ) { setMethods.put(name.substring(3), MethodAnnotation.fromVisitedMethod(this)); } }
Example 2
Source File: BCELifier.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Return a string with the flag settings * @param flags the flags field to interpret * @param location the item type * @return the formatted string * @since 6.0 made public */ public static String printFlags( final int flags, final FLAGS location ) { if (flags == 0) { return "0"; } final StringBuilder buf = new StringBuilder(); for (int i = 0, pow = 1; pow <= Const.MAX_ACC_FLAG_I; i++) { if ((flags & pow) != 0) { if ((pow == Const.ACC_SYNCHRONIZED) && (location == FLAGS.CLASS)) { buf.append(CONSTANT_PREFIX+"ACC_SUPER | "); } else if ((pow == Const.ACC_VOLATILE) && (location == FLAGS.METHOD)) { buf.append(CONSTANT_PREFIX+"ACC_BRIDGE | "); } else if ((pow == Const.ACC_TRANSIENT) && (location == FLAGS.METHOD)) { buf.append(CONSTANT_PREFIX+"ACC_VARARGS | "); } else { if (i < Const.ACCESS_NAMES_LENGTH) { buf.append(CONSTANT_PREFIX+"ACC_").append(Const.getAccessName(i).toUpperCase(Locale.ENGLISH)).append( " | "); } else { buf.append(String.format (CONSTANT_PREFIX+"ACC_BIT %x | ", pow)); } } } pow <<= 1; } final String str = buf.toString(); return str.substring(0, str.length() - 3); }
Example 3
Source File: SerializableIdiom.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void visit(Method obj) { int accessFlags = obj.getAccessFlags(); boolean isSynchronized = (accessFlags & Const.ACC_SYNCHRONIZED) != 0; if (Const.CONSTRUCTOR_NAME.equals(getMethodName()) && "()V".equals(getMethodSig()) && (accessFlags & Const.ACC_PUBLIC) != 0) { hasPublicVoidConstructor = true; } if (!Const.CONSTRUCTOR_NAME.equals(getMethodName()) && isSynthetic(obj)) { foundSynthetic = true; // System.out.println(methodName + isSynchronized); } if ("readExternal".equals(getMethodName()) && "(Ljava/io/ObjectInput;)V".equals(getMethodSig())) { sawReadExternal = true; if (DEBUG && !obj.isPrivate()) { System.out.println("Non-private readExternal method in: " + getDottedClassName()); } } else if ("writeExternal".equals(getMethodName()) && "(Ljava/io/Objectoutput;)V".equals(getMethodSig())) { sawWriteExternal = true; if (DEBUG && !obj.isPrivate()) { System.out.println("Non-private writeExternal method in: " + getDottedClassName()); } } else if ("readResolve".equals(getMethodName()) && getMethodSig().startsWith("()") && isSerializable) { sawReadResolve = true; if (!"()Ljava/lang/Object;".equals(getMethodSig())) { bugReporter.reportBug(new BugInstance(this, "SE_READ_RESOLVE_MUST_RETURN_OBJECT", HIGH_PRIORITY) .addClassAndMethod(this)); } else if (obj.isStatic()) { bugReporter.reportBug(new BugInstance(this, "SE_READ_RESOLVE_IS_STATIC", HIGH_PRIORITY).addClassAndMethod(this)); } else if (obj.isPrivate()) { try { Set<ClassDescriptor> subtypes = AnalysisContext.currentAnalysisContext().getSubtypes2() .getSubtypes(getClassDescriptor()); if (subtypes.size() > 1) { BugInstance bug = new BugInstance(this, "SE_PRIVATE_READ_RESOLVE_NOT_INHERITED", NORMAL_PRIORITY) .addClassAndMethod(this); boolean nasty = false; for (ClassDescriptor subclass : subtypes) { if (!subclass.equals(getClassDescriptor())) { XClass xSub = AnalysisContext.currentXFactory().getXClass(subclass); if (xSub != null && xSub.findMethod("readResolve", "()Ljava/lang/Object;", false) == null && xSub.findMethod("writeReplace", "()Ljava/lang/Object;", false) == null) { bug.addClass(subclass).describe(ClassAnnotation.SUBCLASS_ROLE); nasty = true; } } } if (nasty) { bug.setPriority(HIGH_PRIORITY); } else if (!getThisClass().isPublic()) { bug.setPriority(LOW_PRIORITY); } bugReporter.reportBug(bug); } } catch (ClassNotFoundException e) { bugReporter.reportMissingClass(e); } } } else if ("readObject".equals(getMethodName()) && "(Ljava/io/ObjectInputStream;)V".equals(getMethodSig()) && isSerializable) { sawReadObject = true; if (!obj.isPrivate()) { bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY) .addClassAndMethod(this)); } } else if ("readObjectNoData".equals(getMethodName()) && "()V".equals(getMethodSig()) && isSerializable) { if (!obj.isPrivate()) { bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY) .addClassAndMethod(this)); } } else if ("writeObject".equals(getMethodName()) && "(Ljava/io/ObjectOutputStream;)V".equals(getMethodSig()) && isSerializable) { sawWriteObject = true; if (!obj.isPrivate()) { bugReporter.reportBug(new BugInstance(this, "SE_METHOD_MUST_BE_PRIVATE", isExternalizable ? NORMAL_PRIORITY : HIGH_PRIORITY) .addClassAndMethod(this)); } } if (isSynchronized) { if ("readObject".equals(getMethodName()) && "(Ljava/io/ObjectInputStream;)V".equals(getMethodSig()) && isSerializable) { bugReporter.reportBug(new BugInstance(this, "RS_READOBJECT_SYNC", isExternalizable ? LOW_PRIORITY : NORMAL_PRIORITY) .addClassAndMethod(this)); } else if ("writeObject".equals(getMethodName()) && "(Ljava/io/ObjectOutputStream;)V".equals(getMethodSig()) && isSerializable) { writeObjectIsSynchronized = true; } else { foundSynchronizedMethods = true; } } super.visit(obj); }
Example 4
Source File: FindNakedNotify.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void visit(Method obj) { int flags = obj.getAccessFlags(); synchronizedMethod = (flags & Const.ACC_SYNCHRONIZED) != 0; }
Example 5
Source File: AbstractMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public boolean isSynchronized() { return (getAccessFlags() & Const.ACC_SYNCHRONIZED) != 0; }
Example 6
Source File: AccessFlags.java From commons-bcel with Apache License 2.0 | 4 votes |
public final boolean isSynchronized() { return (access_flags & Const.ACC_SYNCHRONIZED) != 0; }