Skip to content

Commit

Permalink
6846: Parser needs to skip events with no metadata
Browse files Browse the repository at this point in the history
Reviewed-by: egahlin
  • Loading branch information
thegreystone committed Oct 14, 2020
1 parent 7de07b4 commit fea3cc6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -91,8 +91,8 @@ private static boolean isNumber(String string) {
*
* @param vmName
* the JVM name to check.
* @return <tt>true</tt> of it is a JRockit, <tt>false</tt> if it isn't or if was not possible
* to tell.
* @return <code>true</code> of it is a JRockit, <code>false</code> if it isn't or if was not
* possible to tell.
*/
public static boolean isJRockitJVMName(String vmName) {
if (vmName == null) {
Expand All @@ -106,8 +106,8 @@ public static boolean isJRockitJVMName(String vmName) {
*
* @param vmName
* the JVM name to check.
* @return <tt>true</tt> if it is a HotSpot, <tt>false</tt> if it isn't or if was not possible
* to tell.
* @return <code>true</code> if it is a HotSpot, <code>false</code> if it isn't or if was not
* possible to tell.
*/
public static boolean isHotspotJVMName(String vmName) {
if (vmName == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -39,6 +39,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.openjdk.jmc.common.collection.FastAccessNumberMap;
import org.openjdk.jmc.common.unit.ContentType;
Expand Down Expand Up @@ -398,9 +400,12 @@ void init(LoaderContext context) throws InvalidJfrFileException, IOException {
void readEvent(long typeId, IDataInput input) throws InvalidJfrFileException, IOException {
EventTypeEntry entry = eventTypes.get(typeId);
if (entry == null) {
throw new InvalidJfrFileException("Event type with id " + typeId + " was not declared"); //$NON-NLS-1$ //$NON-NLS-2$
// We don't need to do anything here, as the chunk loader will skip to the next event for us.
Logger.getLogger(getClass().getName()).log(Level.WARNING,
"Event type with id " + typeId + " was not declared"); //$NON-NLS-1$ //$NON-NLS-2$
} else {
entry.readEvent(input);
}
entry.readEvent(input);
}

void readConstants(long typeId, IDataInput input, int constantCount) throws InvalidJfrFileException, IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, Datadog, Inc. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The contents of this file are subject to the terms of either the Universal Permissive License
* v 1.0 as shown at http://oss.oracle.com/licenses/upl
*
* or the following license:
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided with
* the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.openjdk.jmc.flightrecorder.test;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.openjdk.jmc.common.item.Aggregators;
import org.openjdk.jmc.common.item.IItemCollection;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.flightrecorder.CouldNotLoadRecordingException;
import org.openjdk.jmc.flightrecorder.test.util.RecordingToolkit;

public class MissingMetadataTest {

@Test
public void testSkipEventWithMissingMetadata() throws IOException, CouldNotLoadRecordingException {
IItemCollection noEvents = RecordingToolkit.getNamedRecording("hs_err_jdk-16.jfr");
IQuantity expected = noEvents.getAggregate(Aggregators.count());
Assert.assertEquals("Recording should not contain any events", expected.longValue(), 0L);
}
}
Binary file not shown.

0 comments on commit fea3cc6

Please sign in to comment.