001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.terminal.report; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021/** 022 * Bounds applied while reading a report, so a hostile or runaway file cannot exhaust memory. 023 * 024 * @param maxFileBytes The largest file that is read; larger files are skipped with a warning. 025 * @param maxTests The most tests kept from one file; reading stops there with a warning. 026 * @param maxNameChars The longest suite or test name kept; longer names are clipped. 027 * @param maxMsgChars The longest failure message kept. 028 * @param maxTraceChars The longest stack trace kept. 029 */ 030public record ReportLimits(long maxFileBytes, int maxTests, int maxNameChars, int maxMsgChars, int maxTraceChars) { 031 032 /** The default limits: 32 MiB, 100,000 tests, 512-char names, 2,000-char messages, 8,000-char traces. */ 033 public static final ReportLimits DEFAULT = new ReportLimits(33_554_432L, 100_000, 512, 2000, 8000); 034 035 /** 036 * Constructor. 037 * 038 * @throws IllegalArgumentException If any value is not positive. 039 */ 040 public ReportLimits { 041 if (maxFileBytes < 1 || maxTests < 1 || maxNameChars < 1 || maxMsgChars < 1 || maxTraceChars < 1) 042 throw iaex("ReportLimits values must all be positive; got %s, %s, %s, %s, %s.", maxFileBytes, maxTests, maxNameChars, maxMsgChars, maxTraceChars); 043 } 044}