Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.regex.Pattern;

import jakarta.jms.ConnectionMetaData;
import org.apache.activemq.command.WireFormatInfo;

/**
* A <CODE>ConnectionMetaData</CODE> object provides information describing
Expand All @@ -35,6 +36,10 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
public static final String PROVIDER_NAME = "ActiveMQ";
public static final String DEFAULT_PLATFORM_DETAILS = "Java";
public static final String PLATFORM_DETAILS;
// Set the max length to WireFormatInfo.MAX_PROPERTY_BUFFER_SIZE (512 bytes)
// Now that we limit property value buffer sizes inside WireFormatInfo we need to
// limit the value from being larger than this, or we would get an exception.
public static final int PLATFORM_DETAILS_MAX_LENGTH = WireFormatInfo.MAX_PROPERTY_BUFFER_SIZE;

public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();

Expand Down Expand Up @@ -157,10 +162,11 @@ public Enumeration<String> getJMSXPropertyNames() {
*
* @return String containing the platform details
*/
private static String getPlatformDetails() {
String details = "java";
// Package scope for testing purposes
static String getPlatformDetails() {
String details = DEFAULT_PLATFORM_DETAILS;
try {
StringBuilder platformInfo = new StringBuilder(128);
final StringBuilder platformInfo = new StringBuilder(128);

platformInfo.append("JVM: ");
platformInfo.append(System.getProperty("java.version"));
Expand All @@ -175,8 +181,10 @@ private static String getPlatformDetails() {
platformInfo.append(", ");
platformInfo.append(System.getProperty("os.arch"));

details = platformInfo.toString();
} catch (Throwable e) {
// truncate to the max allowed length if too long
details = platformInfo.length() > PLATFORM_DETAILS_MAX_LENGTH ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cuts off the details without any indication they were cut off, which is probably fine. I have seen some implementation do this by inserting an ellipsis after a given point and then appending a small bit trailing value such that you get a sort of visual indication that it was clipped. Probably not needed here so just making sure you thought about that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it's fine here, it's off by default and its now 512 and shouldn't really be hit but we could improve it later if needed. This is more of just a fail safe. I doubt anyone even turns this setting on to be honest.

platformInfo.substring(0, PLATFORM_DETAILS_MAX_LENGTH) : platformInfo.toString();
} catch (Throwable ignored) {
}
return details;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class WireFormatInfo implements Command, MarshallAware {
// Max number of properties allowed in the map is 64
static final int MAX_PROPERTY_SIZE = 64;
// Used to validate property values that allocate buffers, limit to 512 bytes
static final int MAX_PROPERTY_BUFFER_SIZE = 512;
public static final int MAX_PROPERTY_BUFFER_SIZE = 512;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch I forgot that you made the default for WireFormatInfo 512 from the original 256

// Do not allow any nested collections in properties
static final int MAX_PROPERTY_DEPTH = 0;
private static final byte[] MAGIC = new byte[] {'A', 'c', 't', 'i', 'v', 'e', 'M', 'Q'};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq;

import static org.apache.activemq.ActiveMQConnectionMetaData.PLATFORM_DETAILS_MAX_LENGTH;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class ActiveMQConnectionMetaDataTest {

@Test
public void testPlatformDetails() {
// static final should match generated from the utility method
assertEquals(ActiveMQConnectionMetaData.PLATFORM_DETAILS,
ActiveMQConnectionMetaData.getPlatformDetails());
}

@Test
public void testPlatformDetailsTruncation() {
String javaVendor = System.getProperty("java.vendor");
try {
System.setProperty("java.vendor", "a".repeat(PLATFORM_DETAILS_MAX_LENGTH + 1));
// ensure we truncate if too large
assertEquals(PLATFORM_DETAILS_MAX_LENGTH,
ActiveMQConnectionMetaData.getPlatformDetails().length());
} finally {
// restore original
System.setProperty("java.vendor", javaVendor);
}
}
}
Loading