The longest Java methods in 13 open-source projects
← Back to Learn · By Ronak Arora · Published · Updated
Only 0.15% of the Java methods and constructors in 13 respected open-source projects are longer than 100 lines — 211 out of 140,090. We ranked the longest of them. The ten longest are all in test or benchmark code, and 131 of the 211 (62%) sit outside production paths. The other 80 are production methods, and they are a small, recognisable set. One project, Jackson Core, accounts for 28 of them.
How we measured
The projects are Guava, Guice, Gson, Jackson Core, Jsoup, Joda-Time, JUnit 5, Mockito, Retrofit, SLF4J and three Apache Commons libraries (Collections, IO and Lang). Each was scanned at a pinned commit listed in the open data file. Only Java files are counted, so Retrofit’s bundled website scripts are left out. Length is the number of lines from a method’s first line to its closing brace, so blank lines and comments inside the method count, and a constructor counts as a method. “Non-production” means a path with a directory named like test, tests, benchmark, examples, docs or vendor, or a file named like FooTest.java.
We re-ran every scan on 19 October 2026 at the same commits. The method and finding totals matched the data file exactly, and every figure in this article comes from that run. One caveat: Guava keeps an android/ copy of much of its source, and 32 of its 66 long methods are in that copy, so many of them are the same method counted twice.
How rare is a long method?
- The median method is 5 lines. About 78% of methods are 10 lines or shorter, 17% run 11 to 25, 3.6% run 26 to 50 and 0.8% run 51 to 100.
- 1,340 methods (1.0%) are over 50 lines, 211 (0.15%) are over 100, and 49 are over 200. Of the 1,340 over 50 lines, 572 are in production paths.
- The count is concentrated: Guava has 66 of the 211, Jackson Core 37, Commons Lang 30, Guice 26, Joda-Time 12 and Gson 9.
Counted as a rate, the order changes. Methods over 100 lines are 0.64% of Jackson Core, 0.33% of Guice, 0.27% of Commons Lang and 0.26% of Gson. They are 0.12% of Guava and Joda-Time, 0.10% of Commons IO, 0.09% of Jsoup and Mockito, 0.08% of Retrofit, 0.07% of Commons Collections and 0.04% of JUnit 5. SLF4J has none.
The longest of all: tables and test bodies
The top of the ranking is not code anyone would call logic:
- Jackson Core,
DoubleToDecimalChecker: four methods named hard0 to hard3 of 5,004, 5,004, 5,004 and 4,549 lines. Each returns a single array of hard-coded double-precision values for a test. - Commons Lang,
ArrayUtilsTest.testSameLengthAll: 1,334 lines of setup and assertions in one test method. - Guava,
CharMatcherBenchmark: populateProb2 at 720 lines and populateProb1 at 633, both in benchmark code. - Commons Lang,
SystemUtilsTest.testJavaVersionMatches: 623 lines.
All of the ten longest methods, and 19 of the 20 longest, are in tests or benchmarks. They are long because they list data or repeat one kind of assertion many times, not because they are tangled. Another 20 of the 211 are methods named suite, the JUnit 3 convention for collecting tests.
The longest production methods
Filtering to production paths leaves 80 methods over 100 lines, which is 0.12% of the 65,473 production methods. The longest are:
- Retrofit,
RequestFactory.parseParameterAnnotation: 456 lines — parses the annotations on a parameter. - Jsoup,
HtmlTreeBuilderState.inBodyStartTag: 357 lines — the HTML parser’s rules for start tags inside the body. - Mockito,
MockMethodAdvice.wrap: 257 lines — bytecode advice for mocked methods. - Jackson Core,
FilteringParserDelegate.nextToken: 242 lines — token filtering inside a JSON parser. - Guice,
FactoryProvider2.FactoryProvider2: 227 lines — a constructor. - Guice,
SingletonScope.scope: 223 lines — singleton scope handling. - Guice,
BindingProcessor.visit: 217 lines — binding processing. - Mockito,
MockMethodAdvice.visitCode: 205 lines — bytecode advice for mocked methods. - Commons Lang,
RandomStringUtils.random: 202 lines — random string generation.
Read down that list and the pattern is clear: parsers and annotation handlers, bytecode instrumentation, and framework internals. Retrofit’s parseParameterAnnotation is an if/else-if chain with one branch for each annotation type, such as Url, Path and Query. Jsoup’s inBodyStartTag follows the HTML specification’s rules for start tags, which are themselves a long list of special cases. In both, the length mirrors the thing being modelled.
Jackson Core is the exception
Jackson Core has 2,631 production methods, and 28 of them (1.06%) are over 100 lines. That is nearly nine times the 0.12% rate across all production code, and it makes Jackson Core 35% of the 80 production methods on the list. It also has the longest median method of the 13 projects, at 8 lines.
The long ones cluster in its parsers. FilteringParserDelegate alone has three, at 242, 190 and 182 lines. ReaderBasedJsonParser._parseNumber2 runs 161 lines and UTF8StreamJsonParser._nextNameMatch 149. That fits a library where hand-written parsing code is written for speed, but a scan can only show where the length is, not why the authors chose it.
Complexity tells a different story
Length is mostly a test and benchmark habit, but branching is mostly a production one. The most complex production methods are Jsoup’s inBodyStartTag at 124, Retrofit’s parseParameterAnnotation at 120, and Commons Lang’s random at 78. Of the 984 Java methods above complexity 10, 844 (86%) are in production paths and only 140 (14%) are not. Put as rates, about 1.3% of production methods pass complexity 10, against 0.19% of test and other non-production methods.
What this means for your own code
- Check the path before the number. A test with a 1,300-line body is a different problem from a 300-line method in production code.
- Long and branchy often means “mirrors a spec”. If a method follows an external grammar or protocol, the useful questions are whether it is tested and whether a new case is easy to add.
- Tables belong in data. A method that returns thousands of literal values is a candidate for a resource file.
- Track the production count. Projects this well maintained still have between none and 28 long production methods each. Zero is not the goal; a steady count is.
- Do not stop at length. A short method can still be tangled, and the complexity numbers above show that branching hides in production code far more than very long code does.
Frequently asked questions
Are constructors counted as methods?
Yes. Guice’s FactoryProvider2 constructor, at 227 lines, is in the list above.
Why is the share so low compared with other languages?
In this data set, 0.15% of Java methods pass 100 lines, against 1.2% of C++ functions and 0.45% of Python functions. These are 13 mature projects with strong conventions, so treat it as a picture of well-kept code and not a language ranking.
Does a long method mean there is a bug?
No. Length is a prompt to look, not a defect. The longest methods here are data tables, test bodies and parsers that mirror a specification, and none of that is wrong by itself. Length matters when a method is hard to test or when its branches have started to hide mistakes.
Which limits does REPO-SIGHT use?
For Java, java-long-method flags methods over 100 lines and java-complex-function flags methods above cyclomatic complexity 10. Treat both as starting points and tune them to your own project.
How do I find the long methods in my project?
Paste a GitHub URL and the report ranks your longest and most complex methods by file. The Java code analyzer page lists what is checked, and how to improve Java code quality shows common fixes.