/*
This method duplicates code in org.apache.el.util.ReflectionUtil. When
making changes keep the code in sync.
517010
static Method getMethod(Class<?> type, Method m) {
        if (m == null || Modifier.isPublic(type.getModifiers())) {
            return m;
        }
        Class<?>[] inf = type.getInterfaces();
        Method mp = null;
        for (int i = 0; i < inf.length; i++) {
            try {
                mp = inf[i].getMethod(m.getName(), m.getParameterTypes());
                mp = getMethod(mp.getDeclaringClass(), mp);
                if (mp != null) {
                    return mp;
                }
            } catch (NoSuchMethodException e) {
                // Ignore
            }
        }
        Class<?> sup = type.getSuperclass();
        if (sup != null) {
            try {
                mp = sup.getMethod(m.getName(), m.getParameterTypes());
                mp = getMethod(mp.getDeclaringClass(), mp);
                if (mp != null) {
                    return mp;
                }
            } catch (NoSuchMethodException e) {
                // Ignore
            }
        }
        return null;
    }
1152959
@Override
    public void sawOpcode(int seen) {

        try {
            stack.precomputation(this);

            if ((seen == Const.INVOKEVIRTUAL) || (seen == Const.INVOKEINTERFACE)) {
                FQMethod key = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());

                Object posObject = characterMethods.get(key);
                if (posObject instanceof Integer) {
                    if (checkSingleParamMethod(((Integer) posObject).intValue()) && !isInlineAppend(key)) {
                        reportBug();
                    }
                } else if ((posObject instanceof IntPair) && checkDoubleParamMethod((IntPair) posObject)) {
                    reportBug();
                }

            } else if (seen == Const.DUP) {
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item itm = stack.getStackItem(0);
                    String duppedSig = itm.getSignature();
                    if (Values.SIG_JAVA_UTIL_STRINGBUILDER.equals(duppedSig) || Values.SIG_JAVA_UTIL_STRINGBUFFER.equals(duppedSig)) {
                        itm.setUserValue(UCPMUserValue.INLINE);
                    }
                }
            } else if ((seen == Const.PUTFIELD) || (((seen == Const.PUTSTATIC) || OpcodeUtils.isAStore(seen)) && (stack.getStackDepth() > 0))) {
                OpcodeStack.Item itm = stack.getStackItem(0);
                itm.setUserValue(null);
            }
        } finally {
            UCPMUserValue uv = callHasInline(seen);

            stack.sawOpcode(this, seen);
            if ((uv == UCPMUserValue.INLINE) && (stack.getStackDepth() > 0)) {
                OpcodeStack.Item itm = stack.getStackItem(0);
                itm.setUserValue(uv);
            }
        }
    }
373643
public ExceptionSet duplicate() {
        ExceptionSet dup = factory.createExceptionSet();
        dup.exceptionSet.clear();
        dup.exceptionSet.or(this.exceptionSet);
        dup.explicitSet.clear();
        dup.explicitSet.or(this.explicitSet);
        dup.size = this.size;
        dup.universalHandler = this.universalHandler;
        dup.commonSupertype = this.commonSupertype;

        return dup;
    }
863582
@Override
    public void visitCode(final Code obj) {
        try {
            localCollections = new HashMap<>();
            localScopeEnds = new HashMap<>();
            localSourceLineAnnotations = new HashMap<>();
            stack.resetForMethodEntry(this);
            super.visitCode(obj);
        } finally {
            localCollections = null;
            localScopeEnds = null;
            localSourceLineAnnotations = null;
        }
    }
1230747
private void checkDuplicates() throws Failure {
        int i;
        Variable v;
        String name;

        for (i = 0; i < vars.length; i++) {
            v = vars[i];
            name = v.getName();
            if (lookup(name) != v) {
                throw new Failure("duplicate variable name: " + name);
            }
        }
    }
446224
@SuppressWarnings("unchecked")
    ViewQueryParameters<K, V> copy() {
        try {
            return (ViewQueryParameters<K, V>) this.clone();
        } catch (CloneNotSupportedException e) {
            //should not reach this code as this class implements Cloneable
            throw new RuntimeException(e);
        }
    }
901697
function it_retains_the_original_state_of_the_instance_duplicated_with_new_scheme()
    {
        $original_uri = (string) $this->getWrappedObject();

        $new_scheme = $this->withScheme("http");

        $this->__toString()->shouldReturn($original_uri);
    }
848100
@Override
    public void visitCode(Code obj) {
        try {
            Method method = getMethod();
            if (method.isSynthetic()) {
                return;
            }

            isBooleanMethod = Type.BOOLEAN.equals(method.getReturnType());
            if (isBooleanMethod || prescreen(method)) {
                catchHandlerPCs = collectExceptions(obj.getExceptionTable());
                if (!catchHandlerPCs.isEmpty()) {
                    stack.resetForMethodEntry(this);
                    catchInfos = new ArrayList<>();
                    lvt = method.getLocalVariableTable();
                    constrainingInfo = null;
                    hasValidFalseReturn = false;
                    catchFalseReturnPC = -1;
                    super.visitCode(obj);

                    if (!hasValidFalseReturn && (catchFalseReturnPC >= 0) && !method.getName().startsWith("is")) {
                        bugReporter.reportBug(new BugInstance(this, BugType.EXS_EXCEPTION_SOFTENING_RETURN_FALSE.name(),
                                NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this,
                                        catchFalseReturnPC));
                    }
                }
            }
        } finally {
            catchInfos = null;
            catchHandlerPCs = null;
            lvt = null;
            constrainingInfo = null;
        }
    }
591911
@Override
    public HttpResponseMessage duplicate() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Duplicating the response message: " + this);
        }

        HttpResponseMessageImpl msg = null;
        HttpObjectFactory factory = getObjectFactory();
        if (null == factory) {
            msg = new HttpResponseMessageImpl();
        } else {
            msg = factory.getResponse();
        }
        msg.setIncoming(isIncoming());
        // set the response specifics
        msg.setStatusCode(this.myStatusCode);
        msg.setReasonPhrase(this.myReasonBytes);

        // set the common object values
        super.duplicate(msg);
        return msg;
    }
655685
private static void checkDuplicates(ImmutableList<SQLPPTriplesMap> mappings)
            throws DuplicateMappingException {

        Set<SQLPPTriplesMap> mappingSet = new HashSet<>(mappings);

        int duplicateCount = mappings.size() - mappingSet.size();

        /**
         * If there are some triplesMaps, finds them
         */
        if (duplicateCount > 0) {
            Set<String> duplicateIds = new HashSet<>();
            int remaining = duplicateCount;
            for (SQLPPTriplesMap mapping : mappings) {
                if (mappingSet.contains(mapping)) {
                    mappingSet.remove(mapping);
                }
                /**
                 * Duplicate
                 */
                else {
                    duplicateIds.add(mapping.getId());
                    if (--remaining == 0)
                        break;
                }
            }
            //TODO: indicate the source
            throw new DuplicateMappingException(String.format("Found %d duplicates in the following ids: %s",
                    duplicateCount, duplicateIds.toString()));
        }
    }
951600
@Override
	public void visitCode(final Code obj) {
		try {
			stack.resetForMethodEntry(this);
			super.visitCode(obj);
		} catch (StopOpcodeParsingException e) {
			// ok, move on to the next method
		}
	}
593034
@Override
    public void visitCode(Code obj) {
        stack.resetForMethodEntry(this);
        exemptExecutors.clear();

        if (!hangingFieldCandidates.isEmpty()) {
            isInitializer = (Values.STATIC_INITIALIZER.equals(methodName) || Values.CONSTRUCTOR.equals(methodName));
            super.visitCode(obj);
        }
    }
646654
private void checkDuplicateTokens(MutableTemplateInfo templateInfo) throws TemplateException {
        List<String> allTokenNames = new ArrayList<String>();
        for (TemplateTokenInfo tokenInfo : templateInfo.tokenInfos) {
            if (allTokenNames.contains(tokenInfo.getName())) {
                throw new TemplateException("Token name '"
                        + tokenInfo.getName() + "' duplicated in template '" +
                        templateInfo.name + "'.");
            } else {
                allTokenNames.add(tokenInfo.getName());
            }
        }
    }
155842
@Override
    public void visitCode(final Code obj) {
        if (obj.getCode() != null) {
            stack.resetForMethodEntry(this);
            sawLDCEmpty = false;
            super.visitCode(obj);
        }
    }
126459
void initInputsByIdMap() {
    inputsById.clear();
    for (CompilerInput input : externs) {
      InputId id = input.getInputId();
      CompilerInput previous = putCompilerInput(id, input);
      if (previous != null) {
        report(JSError.make(DUPLICATE_EXTERN_INPUT, input.getName()));
      }
    }
    for (CompilerInput input : moduleGraph.getAllInputs()) {
      InputId id = input.getInputId();
      CompilerInput previous = putCompilerInput(id, input);
      if (previous != null) {
        report(JSError.make(DUPLICATE_INPUT, input.getName()));
      }
    }
  }
1167539
private void duplicateContent(final String spaceId,
                                  final String contentId,
                                  final String sourceChecksum,
                                  final Map<String, String> sourceProperties)
        throws TaskExecutionFailedException {
        log.info("Duplicating " + contentId + " in space " + spaceId +
                 " in account " + dupTask.getAccount());

        ChecksumUtil checksumUtil = new ChecksumUtil(MD5);
        boolean localChecksumMatch = false;
        int attempt = 0;

        File localFile = null;
        while (!localChecksumMatch && attempt < 3) {
            // Get content stream
            try (InputStream sourceStream = getSourceContent(spaceId, contentId)) {
                // Cache content locally
                localFile = cacheContent(sourceStream);
                // Check content
                String localChecksum = checksumUtil.generateChecksum(localFile);
                if (sourceChecksum.equals(localChecksum)) {
                    localChecksumMatch = true;
                } else {
                    cleanup(localFile);
                }
            } catch (Exception e) {
                log.warn("Error generating checksum for source content: " + e.getMessage(), e);
            }
            attempt++;
        }

        // Put content
        if (localChecksumMatch) {
            putDestinationContent(spaceId,
                                  contentId,
                                  sourceChecksum,
                                  sourceProperties,
                                  localFile);
            log.info(
                "Successfully duplicated id={} dup_size={} space={} account={}",
                contentId,
                localFile.length(),
                spaceId, dupTask.getAccount());
        } else {
            cleanup(localFile);
            String msg = "Unable to retrieve content which matches the" +
                         " expected source checksum of: " + sourceChecksum;
            throw new DuplicationTaskExecutionFailedException(buildFailureMessage(msg));
        }
        cleanup(localFile);
    }
126765
@Override
    public void sawOpcode(int seen) {
        boolean reset = true;
        switch (state) { // TODO: Refactor this to use state pattern, not nested
                         // switches
            case SEEN_NOTHING:
                reset = sawOpcodeAfterNothing(seen);
            break;

            case SEEN_ALOAD:
                reset = sawOpcodeAfterLoad(seen);
            break;

            case SEEN_GETFIELD:
                reset = sawOpcodeAfterGetField(seen);
            break;

            case SEEN_DUAL_LOADS:
                reset = sawOpcodeAfterDualLoads(seen);
            break;

            case SEEN_INVOKEVIRTUAL:
                if (seen == Const.INVOKEVIRTUAL) {
                    checkForSGSU();
                }
            break;
        }

        if (reset) {
            beanReference1 = null;
            beanReference2 = null;
            propType = null;
            propName = null;
            sawField = false;
            state = State.SEEN_NOTHING;
        }
    }