@Test public void parse_rejected_big_file() { exceptionRule.expect(ParseException.class); exceptionRule.expectMessage("The file size is too big and should be excluded, its size is 700028 (maximum allowed is 700000 bytes)"); GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); String code = "package main\n" + "func foo() {\n" + "}\n"; String bigCode = code + new String(new char[700_000]).replace("\0", "\n"); converter.parse(bigCode); }
@Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } }
GoConverter implements ASTConverter { @Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } } }
GoConverter implements ASTConverter { @Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } } GoConverter(File workDir);   GoConverter(Command command); }
GoConverter implements ASTConverter { @Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } } GoConverter(File workDir);   GoConverter(Command command); @Override Tree parse(String content); }
GoConverter implements ASTConverter { @Override public Tree parse(String content) { if (content.length() > MAX_SUPPORTED_SOURCE_FILE_SIZE) { throw new ParseException("The file size is too big and should be excluded," + " its size is " + content.length() + " (maximum allowed is " + MAX_SUPPORTED_SOURCE_FILE_SIZE + " bytes)"); } try { return JsonTree.fromJson(executeGoToJsonProcess(content)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ParseException("Go parser external process interrupted: " + e.getMessage(), null, e); } catch (IOException e) { throw new ParseException(e.getMessage(), null, e); } } GoConverter(File workDir);   GoConverter(Command command); @Override Tree parse(String content);  }