private synchronized void updateAlarms() { // activeAlarms.clear(); for (TagBlankEntity tagBlankEntity : deviceEntity.getTagBlankEntities()) { for (AlarmBlank alarmBlank : tagBlankEntity.getAlarmBlanks()) { StringBuffer sb = new StringBuffer(); try { sb.append(values.get(tagBlankEntity.getTagDescr()).getRegister()); sb.append(alarmBlank.getCondition()); String script = sb.toString(); Boolean res = (Boolean) AlarmUtil.getInstance().getScriptEngine().eval(script); Alarm alarm = new Alarm(alarmBlank); if (res == true) { if (activeAlarms.contains(alarm)) { continue; } else { activeAlarms.add(alarm); AlarmEntity alarmEntity = new AlarmEntity(); alarmEntity.setAlarmBlank(alarmBlank); alarmEntity.setAlarmTime(alarm.getStartTime()); DataHelper.getInstance().saveAlarm(alarmEntity); } } else { if (activeAlarms.contains(alarm)) { activeAlarms.remove(alarm); } } } catch (RuntimeException ex) { ex.printStackTrace(); } catch (ScriptException e) { e.printStackTrace(); } } } }
@Ignore("For development only") @Test @SuppressWarnings({"UnusedDeclaration"}) public void testGenerify() { List list = Collections.singletonList("foo"); @SuppressWarnings({"unchecked"}) Set set = new HashSet(list); List<String> strs0 = CollectionUtil.generify(list, String.class); List<Object> objs0 = CollectionUtil.generify(list, String.class); // List<String> strs01 = CollectionUtil.generify(list, Object.class); // Not okay try { List<String> strs1 = CollectionUtil.generify(set, String.class); // Not ok, runtime CCE unless set is null } catch (RuntimeException e) { e.printStackTrace(); } try { ArrayList<String> strs01 = CollectionUtil.generify(list, String.class); // Not ok, runtime CCE unless list is null } catch (RuntimeException e) { e.printStackTrace(); } Set<String> setstr1 = CollectionUtil.generify(set, String.class); Set<Object> setobj1 = CollectionUtil.generify(set, String.class); try { Set<Object> setobj44 = CollectionUtil.generify(list, String.class); // Not ok, runtime CCE unless list is null } catch (RuntimeException e) { e.printStackTrace(); } List<String> strs2 = CollectionUtil.<List<String>, String>generify2(list); List<Object> objs2 = CollectionUtil.<List<Object>, String>generify2(list); // List<String> morestrs = CollectionUtil.<List<Object>, String>generify2(list); // Not // ok try { List<String> strs3 = CollectionUtil.<List<String>, String>generify2( set); // Not ok, runtime CCE unless set is null } catch (RuntimeException e) { e.printStackTrace(); } }
protected void fireChangeListeners() { if (changeListeners == null) return; for (int a = 0; a < changeListeners.size(); a++) { ChangeListener l = (ChangeListener) changeListeners.get(a); try { l.stateChanged(new ChangeEvent(this)); } catch (RuntimeException e) { e.printStackTrace(); } } }
public boolean writeClasses(ConstantPool consts, ConstantPool sharedconsts) { ClassClass classes[] = ClassClass.getClassVector(classMaker); ClassClass.setTypes(); // write out some constant pool stuff here, writeProlog(); try { writeAllNativeTables(classes); } catch (RuntimeException e) { out.flush(); System.out.println(e); e.printStackTrace(System.out); formatError = true; } writeEpilog(); return (!formatError) && (!out.checkError()); }
private void init() { soundPlayer = new SoundPlayer(); soundPlayer.startBackgroundMusic(); try { emptyCursor = Toolkit.getDefaultToolkit() .createCustomCursor( new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "empty"); } catch (RuntimeException e) { e.printStackTrace(); } setFocusTraversalKeysEnabled(false); requestFocus(); // hide cursor, since we're drawing our own one setCursor(emptyCursor); }
/* * public List<NodeInfo> queryIndex( String indexId, String queryString ) * throws ParseException, IOException { return queryIndex(indexId, * this.queryConstructor.construct(getEnvironment(indexId), queryString)); } * * * public List<NodeInfo> queryIndex( String indexId, Query query ) throws * IOException { return new Querier(getEnvironment(indexId)).query(query); } */ public String highlightQuery(Integer queryId, String fieldName, String text) { // return text; if (null == this.queryHighlighter) { // sort of lazy init if we forgot to specify more advanced // highlighter this.setQueryHighlighter(new QueryHighlighter()); } QueryInfo queryInfo = this.queryPool.getQueryInfo(queryId); try { return queryHighlighter .setEnvironment(getEnvironment(queryInfo.getIndexId())) .highlightQuery(queryInfo, fieldName, text); } catch (RuntimeException e) { e.printStackTrace(); logger.debug("DEBUG1!!->" + queryId); logger.error("ERROR!!->"); logger.error("ERROR12!!->" + queryInfo); logger.error("ERROR2!!->" + queryInfo.getIndexId()); logger.error("ERROR3!!->" + getEnvironment(queryInfo.getIndexId())); } return null; }
public JSSA(Type.Class c, DataInput in, ConstantPool cp) throws IOException { super(c, in, cp); local = new Expr[maxLocals]; stack = new Expr[maxStack]; int n = 0; if (!isStatic()) local[n++] = new Argument("this", method.getDeclaringClass()); for (int i = 0; i < this.method.getNumArgs(); i++) local[n++] = new Argument("arg" + i, this.method.getArgType(i)); for (int i = 0; i < size(); i++) { int op = get(i); Object arg = getArg(i); try { Object o = addOp(op, arg); if (o != null) { ops[numOps] = o; ofs[numOps++] = i; } } catch (RuntimeException e) { System.err.println("Had a problem at PC: " + i + " of " + method); e.printStackTrace(); throw new IOException("invalid class file"); } } }
/** * Parses the header of a wind field block * * @param input String containing the input line * @return */ private List<Object> processHeader(String input) { int i = 0; List<Object> arr = new ArrayList<Object>(); Scanner scanner = new Scanner(input).useLocale(Locale.ENGLISH); scanner.useDelimiter(" "); try { while (scanner.hasNext()) { if (i == 0) { arr.add(scanner.next(HEADER_START_PATTERN)); i++; continue; } arr.add(scanner.nextDouble()); i++; } } catch (RuntimeException e) { logger.error("RuntimeException occured" + e); e.printStackTrace(); scanner.close(); } return arr; }
/** * Parses the line as a line full of wind vector pairs. * * @param input String containing the input line * @return * @throws RuntimeException */ private List<Object> processLine(String input) { int i = 0; List<Object> arr = new ArrayList<Object>(); Scanner scanner = new Scanner(input).useLocale(Locale.ENGLISH); scanner.useDelimiter(" "); try { while (scanner.hasNext()) { // Do we have the row identifier (the latitude)? if (i == 0) { arr.add(scanner.nextDouble()); i++; continue; } // We should now only have some wind vectors left WindVector v; try { v = new WindVector(scanner.nextDouble(), scanner.nextDouble()); } catch (NoSuchElementException e) { logger.error("FATAL! Input file contains a incomplete value pair!"); e.printStackTrace(); throw new RuntimeException("FATAL! Input file contains a incomplete value pair!"); } arr.add(v); i++; } } catch (RuntimeException e) { logger.error("Runtime exception occured!"); e.printStackTrace(); scanner.close(); } return arr; }
@Override protected Result doRun(final BuildListener listener) throws Exception { PrintStream logger = listener.getLogger(); try { EnvVars envVars = getEnvironment(listener); Config config = IvyConfig.provider.getConfigById(project.getSettings()); if (config != null) { FilePath tmp = getWorkspace().createTextTempFile("ivy", "xml", config.content); settings = tmp.getRemote(); addAction(new CleanTempFilesAction(settings)); } else { String settingsFile = project.getIvySettingsFile(); if (settingsFile != null) { settings = getWorkspace().child(settingsFile).getRemote(); } } if (!project.isAggregatorStyleBuild()) { // start module builds parseIvyDescriptorFiles(listener, logger, envVars); Set<IvyModule> triggeredModules = new HashSet<IvyModule>(); if (!project.isIncrementalBuild() || IvyModuleSetBuild.this.getChangeSet().isEmptySet()) { for (IvyModule module : project.sortedActiveModules) { // Don't trigger builds if we've already triggered // one // of their dependencies. // It's safe to just get the direct dependencies // since // the modules are sorted in dependency order. List<AbstractProject> ups = module.getUpstreamProjects(); boolean triggerBuild = true; for (AbstractProject upstreamDep : ups) { if (triggeredModules.contains(upstreamDep)) { triggerBuild = false; break; } } if (triggerBuild) { logger.println("Triggering " + module.getModuleName()); module.scheduleBuild( new ParameterizedUpstreamCause( ((Run<?, ?>) IvyModuleSetBuild.this), IvyModuleSetBuild.this.getActions(ParametersAction.class))); } triggeredModules.add(module); } } else { for (IvyModule module : project.sortedActiveModules) { // If there are changes for this module, add it. // Also add it if we've never seen this module // before, // or if the previous build of this module // failed or was unstable. boolean triggerBuild = false; if ((module.getLastBuild() == null) || (!getChangeSetFor(module).isEmpty()) || (module.getLastBuild().getResult().isWorseThan(Result.SUCCESS))) { triggerBuild = true; List<AbstractProject> ups = module.getUpstreamProjects(); for (AbstractProject upstreamDep : ups) { if (triggeredModules.contains(upstreamDep)) { triggerBuild = false; triggeredModules.add(module); break; } } } if (triggerBuild) { logger.println("Triggering " + module.getModuleName()); module.scheduleBuild( new ParameterizedUpstreamCause( ((Run<?, ?>) IvyModuleSetBuild.this), IvyModuleSetBuild.this.getActions(ParametersAction.class))); triggeredModules.add(module); } } } } else { // do builds here try { List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(); for (BuildWrapper w : project.getBuildWrappersList()) wrappers.add(w); ParametersAction parameters = getAction(ParametersAction.class); if (parameters != null) parameters.createBuildWrappers(IvyModuleSetBuild.this, wrappers); for (BuildWrapper w : wrappers) { Environment e = w.setUp(IvyModuleSetBuild.this, launcher, listener); if (e == null) return Result.FAILURE; buildEnvironments.add(e); e.buildEnvVars(envVars); // #3502: too late for // getEnvironment to do // this } if (!preBuild(listener, project.getPublishers())) return Result.FAILURE; Properties additionalProperties = null; if (project.isIncrementalBuild()) { parseIvyDescriptorFiles(listener, logger, envVars); List<String> changedModules = new ArrayList<String>(); for (IvyModule m : project.sortedActiveModules) { // Check if incrementalBuild is selected and that // there are changes - // we act as if incrementalBuild is not set if there // are no changes. if (!IvyModuleSetBuild.this.getChangeSet().isEmptySet()) { // If there are changes for this module, add it. if (!getChangeSetFor(m).isEmpty()) { changedModules.add(m.getModuleName().name); } } } if (project.isAggregatorStyleBuild()) { additionalProperties = new Properties(); additionalProperties.put( project.getChangedModulesProperty() == null ? "hudson.ivy.changedModules" : project.getChangedModulesProperty(), StringUtils.join(changedModules, ',')); } } IvyBuilderType ivyBuilderType = project.getIvyBuilderType(); hudson.tasks.Builder builder = ivyBuilderType.getBuilder(additionalProperties, null, buildEnvironments); logger.println( "Building project with " + ivyBuilderType.getDescriptor().getDisplayName()); if (builder.perform(IvyModuleSetBuild.this, launcher, listener)) return Result.SUCCESS; return Result.FAILURE; } finally { // tear down in reverse order boolean failed = false; for (int i = buildEnvironments.size() - 1; i >= 0; i--) { if (!buildEnvironments.get(i).tearDown(IvyModuleSetBuild.this, listener)) { failed = true; } } buildEnvironments = null; // WARNING The return in the finally clause will trump // any return before if (failed) return Result.FAILURE; } } return null; } catch (AbortException e) { if (e.getMessage() != null) listener.error(e.getMessage()); return Result.FAILURE; } catch (InterruptedIOException e) { e.printStackTrace(listener.error("Aborted Ivy execution for InterruptedIOException")); return Result.ABORTED; } catch (InterruptedException e) { e.printStackTrace(listener.error("Aborted Ivy execution for InterruptedException")); return Result.ABORTED; } catch (IOException e) { e.printStackTrace(listener.error(Messages.IvyModuleSetBuild_FailedToParseIvyXml())); return Result.FAILURE; } catch (RunnerAbortedException e) { return Result.FAILURE; } catch (RuntimeException e) { // bug in the code. e.printStackTrace( listener.error( "Processing failed due to a bug in the code. Please report this to [email protected]")); logger.println("project=" + project); logger.println("project.getModules()=" + project.getModules()); throw e; } }
@Override public void run() { FeedMedia media = DBReader.getFeedMedia(DownloadService.this, request.getFeedfileId()); if (media == null) { throw new IllegalStateException("Could not find downloaded media object in database"); } boolean chaptersRead = false; media.setDownloaded(true); media.setFile_url(request.getDestination()); // Get duration MediaMetadataRetriever mmr = null; try { mmr = new MediaMetadataRetriever(); mmr.setDataSource(media.getFile_url()); String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); media.setDuration(Integer.parseInt(durationStr)); if (BuildConfig.DEBUG) Log.d(TAG, "Duration of file is " + media.getDuration()); } catch (NumberFormatException e) { e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } finally { if (mmr != null) { mmr.release(); } } if (media.getItem().getChapters() == null) { ChapterUtils.loadChaptersFromFileUrl(media); if (media.getItem().getChapters() != null) { chaptersRead = true; } } try { if (chaptersRead) { DBWriter.setFeedItem(DownloadService.this, media.getItem()).get(); } DBWriter.setFeedMedia(DownloadService.this, media).get(); if (!DBTasks.isInQueue(DownloadService.this, media.getItem().getId())) { DBWriter.addQueueItem(DownloadService.this, media.getItem().getId()).get(); } } catch (ExecutionException e) { e.printStackTrace(); status = new DownloadStatus( media, media.getEpisodeTitle(), DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage()); } catch (InterruptedException e) { e.printStackTrace(); status = new DownloadStatus( media, media.getEpisodeTitle(), DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage()); } saveDownloadStatus(status); sendDownloadHandledIntent(); numberOfDownloads.decrementAndGet(); queryDownloadsAsync(); }
public ArrayList<Pair<String, Counter<String>>> compileUsageForAllColumns( int minLength, int maxLength, int maxLines) { if (maxLines < 0) maxLines = Integer.MAX_VALUE; int nTillReport = 100000; int nObjsRead = 0; int nObjsReadTotal = 0; ArrayList<Pair<String, Counter<String>>> returnCounts = new ArrayList<Pair<String, Counter<String>>>(); try { int objNumCol = DumpColumnConfigInfo.getMuseumIdColumnIndex(); DumpColumnConfigInfo[] colDumpInfo = null; try { colDumpInfo = DumpColumnConfigInfo.getAllColumnInfo(columnNames); } catch (IllegalArgumentException iae) { String msg = "Mismatched columns between metadata configuration and metadata file.\n" + iae.getLocalizedMessage(); debug(0, msg); throw new RuntimeException(msg); } int nCols = columnNames.length; boolean[] skipCol = new boolean[nCols]; int[] countIndexes = new int[nCols]; for (int iCol = 0; iCol < nCols; iCol++) { if (!(skipCol[iCol] = !colDumpInfo[iCol].columnMinedForAnyFacet())) { countIndexes[iCol] = returnCounts.size(); returnCounts.add( new Pair<String, Counter<String>>(columnNames[iCol], new Counter<String>())); } else { countIndexes[iCol] = -1; } } resetToLine1(); Pair<Integer, ArrayList<String>> objInfo = null; while ((objInfo = getNextObjectAsColumns()) != null) { int currID = objInfo.getFirst(); ArrayList<String> objStrings = objInfo.getSecond(); assert (objStrings.size() == nCols) : "Bad parse for obj:" + currID; // Have a complete line. Check for validity String objNumStr = objStrings.get(objNumCol); if (DumpColumnConfigInfo.objNumIsValid(objNumStr)) { nObjsReadTotal++; if (++nObjsRead >= nTillReport) { nObjsRead = 0; debug(1, "MDR.compileUsageForAllColumns: read: " + nObjsReadTotal + " objects"); } for (int iCol = 1; iCol < nCols; iCol++) { if (skipCol[iCol]) // Do not bother with misc cols continue; String source = objStrings.get(iCol); if ((source.length() >= minLength) && (source.length() < maxLength)) { ArrayList<Pair<String, ArrayList<String>>> tokenList = ConfigStringUtils.prepareSourceTokens(source, colDumpInfo[iCol]); for (Pair<String, ArrayList<String>> pair : tokenList) { String subtoken = pair.getFirst().trim(); if (subtoken.length() > 1) returnCounts.get(countIndexes[iCol]).getSecond().incrementCount(subtoken, 1); } } } } } } catch (RuntimeException e) { e.printStackTrace(); } return returnCounts; }
public Counter<String> compileUsageForColumn( int iCol, int minLength, int maxLength, int maxLines, StringBuilder statusSB) { Counter<String> vocabCounts = null; int nLinesEmpty = 0; int nLinesTooLong = 0; int reportFreq = 10000; vocabCounts = new Counter<String>(); // noiseTokens.add("each"); if (maxLines < 0) maxLines = Integer.MAX_VALUE; if (iCol < 1) throw new RuntimeException("Illegal column index: " + iCol); try { DumpColumnConfigInfo colDumpInfo = null; try { colDumpInfo = DumpColumnConfigInfo.GetColInfo(columnNames[iCol], "Compile Usage"); } catch (IllegalArgumentException iae) { String msg = "Problem with metadata configuration.\n" + iae.getLocalizedMessage(); debug(0, msg); throw new RuntimeException(msg); } resetToLine1(); String token = null; while (((token = getNextLineColumn(iCol)) != null) && (currLine < maxLines)) { if (currLine % reportFreq == 0) { debug( 1, "MDR.compileUsageForColumn(" + iCol + ") read " + currLine + " lines so far..." + "\n Skipped " + nLinesEmpty + " empty lines and " + nLinesTooLong + " too long lines" + "\n Found " + vocabCounts.size() + " distinct tokens (a total of: " + vocabCounts.totalCount() + " tokens)"); } if (token.length() < minLength) { nLinesEmpty++; continue; } if (token.length() > maxLength) { nLinesTooLong++; continue; } ArrayList<Pair<String, ArrayList<String>>> tokenList = ConfigStringUtils.prepareSourceTokens(token, colDumpInfo); for (Pair<String, ArrayList<String>> pair : tokenList) { String subtoken = pair.getFirst(); vocabCounts.incrementCount(subtoken, 1); } } } catch (RuntimeException e) { e.printStackTrace(); } debug( 1, "MDR.compileUsageForColumn(" + iCol + ") read " + currLine + " lines." + "\n Skipped " + nLinesEmpty + " empty lines and " + nLinesTooLong + " too long lines" + "\n Found " + vocabCounts.size() + " distinct tokens (a total of: " + vocabCounts.totalCount() + " tokens)"); if (statusSB != null) { statusSB.append("Read "); statusSB.append(currLine); statusSB.append(" lines. Found "); statusSB.append(vocabCounts.size()); statusSB.append(" distinct tokens"); } return vocabCounts; }
/* * First algorithm of Nopol, * build the initial model * apply only one modification * build * try to find patch */ private List<Patch> solveWithMultipleBuild( Collection<Statement> statements, Map<SourceLocation, List<TestResult>> testListPerStatement) { List<Patch> patches = new ArrayList<>(); for (Iterator<Statement> iterator = statements.iterator(); iterator.hasNext() && // limit the execution time System.currentTimeMillis() - startTime <= TimeUnit.MINUTES.toMillis(Config.INSTANCE.getMaxTime()); ) { Statement statement = iterator.next(); if (((StatementExt) statement).getEf() == 0) { continue; } /*if(((StatementExt)statement).getNf() != 0) { continue; }*/ try { if (isInTest(statement)) continue; NoPol.currentStatement = statement; logger.debug("Analysing {}", statement); SourceLocation sourceLocation = new SourceLocation( statement.getMethod().getParent().getName(), statement.getLineNumber()); Synthesizer synth = new SynthesizerFactory(sourceFiles, spooner, type).getFor(sourceLocation); if (synth == Synthesizer.NO_OP_SYNTHESIZER) { continue; } List<TestResult> tests = testListPerStatement.get(sourceLocation); Set<String> failingClassTest = new HashSet<>(); for (int i = 0; i < tests.size(); i++) { TestResult testResult = tests.get(i); if (!testResult.wasSuccessful()) { failingClassTest.add(testResult.getName().split("#")[0]); } } Collection<TestCase> failingTest = failingTests(failingClassTest.toArray(new String[0]), new URLClassLoader(classpath)); if (failingTest.isEmpty()) { continue; } Patch patch = synth.buildPatch(classpath, tests, failingTest, Config.INSTANCE.getMaxTimeBuildPatch()); if (isOk(patch, gZoltar.getGzoltar().getTestResults(), synth.getProcessor())) { patches.add(patch); if (isSinglePatch()) { break; } } else { logger.debug("Could not find a patch in {}", statement); } } catch (RuntimeException re) { re.printStackTrace(); } } return patches; }
// private static final ArrayList<String> ignoreSuffixes = new // ArrayList<>(Arrays.asList("Customizer", "BeanInfo")); // private static final int ignoreSuffixesSize = ignoreSuffixes.size(); // TODO: does this need synchronized? slows it down... private Class<?> loadClassInternal(String className, boolean resolve) throws ClassNotFoundException { /* This may not be a good idea, Groovy looks for all sorts of bogus class name but there may be a reason so not doing this or looking for other patterns: for (int i = 0; i < ignoreSuffixesSize; i++) { String ignoreSuffix = ignoreSuffixes.get(i); if (className.endsWith(ignoreSuffix)) { ClassNotFoundException cfne = new ClassNotFoundException("Ignoring Groovy style bogus class name " + className); classCache.put(className, cfne); throw cfne; } } */ Class<?> c = null; try { // classes handled opposite of resources, try parent first (avoid java.lang.LinkageError) try { ClassLoader cl = getParent(); c = cl.loadClass(className); } catch (ClassNotFoundException | NoClassDefFoundError e) { // do nothing, common that class won't be found if expected in additional JARs and class // directories } catch (RuntimeException e) { e.printStackTrace(); throw e; } if (c == null) { try { if (trackKnown) { File classFile = knownClassFiles.get(className); if (classFile != null) c = makeClass(className, classFile); if (c == null) { JarEntryInfo jei = knownClassJarEntries.get(className); if (jei != null) c = makeClass(className, jei.file, jei.entry, jei.jarLocation); } } // not found in known? search through all c = findJarClass(className); } catch (Exception e) { System.out.println( "Error loading class [" + className + "] from additional jars: " + e.toString()); e.printStackTrace(); } } // System.out.println("Loading class name [" + className + "] got class: " + c); if (c == null) { ClassNotFoundException cnfe = new ClassNotFoundException("Class " + className + " not found."); if (rememberClassNotFound) { // Groovy seems to look, then re-look, for funny names like: // groovy.lang.GroovyObject$java$io$org$moqui$entity$EntityListIterator // java.io.org$moqui$entity$EntityListIterator // groovy.util.org$moqui$context$ExecutionContext // org$moqui$context$ExecutionContext // Groovy does similar with *Customizer and *BeanInfo; so just don't remember any of these // In general it seems that anything with a '$' needs to be excluded if (!className.contains("$") && !className.endsWith("Customizer") && !className.endsWith("BeanInfo")) { ClassNotFoundException existingExc = notFoundCache.putIfAbsent(className, cnfe); if (existingExc != null) throw existingExc; } } throw cnfe; } else { classCache.put(className, c); } return c; } finally { if (c != null && resolve) resolveClass(c); } }