diff --git a/config/makeprops.py b/config/makeprops.py index a310214ddd4..a8d506a0abd 100755 --- a/config/makeprops.py +++ b/config/makeprops.py @@ -273,9 +273,9 @@ def openFiles(self): {{ const char* name; const bool prefixOnly; + const bool isOptIn; const Property* properties; const int length; - const bool isOptIn; }}; class PropertyNames @@ -330,9 +330,9 @@ def writePropertyArray(self, propertyArray): {{ .name="{name}", .prefixOnly={prefixOnly}, + .isOptIn={isOptIn}, .properties={name}PropsData, - .length={len(propertyArray.properties)}, - .isOptIn={isOptIn} + .length={len(propertyArray.properties)} }}; """) @@ -408,6 +408,7 @@ def fix(self, propertyName): def writePropertyArray(self, propertyArray): name = propertyArray.name prefixOnly = "true" if propertyArray.prefixOnly else "false" + isOptIn = "true" if propertyArray.isOptIn else "false" properties = ( "\n " + ",\n ".join(propertyArray.properties) if propertyArray.properties @@ -418,6 +419,7 @@ def writePropertyArray(self, propertyArray): f""" public static final PropertyArray {name}Props = new PropertyArray( "{name}", {prefixOnly}, + {isOptIn}, new Property[] {{{properties} }}); @@ -505,6 +507,7 @@ def fix(self, propertyName): def writePropertyArray(self, propertyArray): name = propertyArray.name prefixOnly = "true" if propertyArray.prefixOnly else "false" + isOptIn = "true" if propertyArray.isOptIn else "false" properties = ( f"\n {",\n ".join(propertyArray.properties)}\n " if propertyArray.properties @@ -515,6 +518,7 @@ def writePropertyArray(self, propertyArray): internal static PropertyArray {name}Props = new( "{name}", {prefixOnly}, + {isOptIn}, [{properties}]); """) @@ -583,6 +587,7 @@ def fix(self, propertyName): def writePropertyArray(self, propertyArray): name = propertyArray.name prefixOnly = "true" if propertyArray.prefixOnly else "false" + isOptIn = "true" if propertyArray.isOptIn else "false" properties = ( "\n " + ",\n ".join(propertyArray.properties) if propertyArray.properties @@ -591,7 +596,7 @@ def writePropertyArray(self, propertyArray): # We assign the properties to the property array after creating it so that we can reference the array # in the properties themselves self.srcFile.write(f"""\ -PropertyNames.{name}Props = new PropertyArray("{name}", {prefixOnly}); +PropertyNames.{name}Props = new PropertyArray("{name}", {prefixOnly}, {isOptIn}); PropertyNames.{name}Props.properties = [{properties} ]; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index aeeae2e42d5..4b679d043b7 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -327,13 +327,13 @@ Ice::ObjectAdapterI::destroy() noexcept // // Remove object references (some of them cyclic). // - _instance = 0; - _threadPool = 0; - _routerInfo = 0; + _instance = nullptr; + _threadPool = nullptr; + _routerInfo = nullptr; _publishedEndpoints.clear(); - _locatorInfo = 0; - _reference = 0; - _objectAdapterFactory = 0; + _locatorInfo = nullptr; + _reference = nullptr; + _objectAdapterFactory = nullptr; _state = StateDestroyed; _conditionVariable.notify_all(); @@ -582,7 +582,6 @@ optional Ice::ObjectAdapterI::getLocator() const noexcept { lock_guard lock(_mutex); - checkForDeactivation(); return _locatorInfo ? optional(_locatorInfo->getLocator()) : nullopt; } diff --git a/cpp/src/Ice/Properties.cpp b/cpp/src/Ice/Properties.cpp index 484c6a77ea6..afd9e7569b9 100644 --- a/cpp/src/Ice/Properties.cpp +++ b/cpp/src/Ice/Properties.cpp @@ -603,7 +603,7 @@ Ice::Properties::parseOptions(string_view prefix, const StringSeq& options) } else { - unmatched.emplace_back(opt); + unmatched.push_back(std::move(opt)); } } diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index ca567bcb79f..d3a1ca4393a 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -26,9 +26,9 @@ const PropertyArray PropertyNames::ProxyProps { .name="Proxy", .prefixOnly=false, + .isOptIn=false, .properties=ProxyPropsData, - .length=9, - .isOptIn=false + .length=9 }; const Property ConnectionPropsData[] = @@ -45,9 +45,9 @@ const PropertyArray PropertyNames::ConnectionProps { .name="Connection", .prefixOnly=true, + .isOptIn=false, .properties=ConnectionPropsData, - .length=6, - .isOptIn=false + .length=6 }; const Property ThreadPoolPropsData[] = @@ -63,9 +63,9 @@ const PropertyArray PropertyNames::ThreadPoolProps { .name="ThreadPool", .prefixOnly=true, + .isOptIn=false, .properties=ThreadPoolPropsData, - .length=5, - .isOptIn=false + .length=5 }; const Property ObjectAdapterPropsData[] = @@ -88,9 +88,9 @@ const PropertyArray PropertyNames::ObjectAdapterProps { .name="ObjectAdapter", .prefixOnly=true, + .isOptIn=false, .properties=ObjectAdapterPropsData, - .length=12, - .isOptIn=false + .length=12 }; const Property LMDBPropsData[] = @@ -103,9 +103,9 @@ const PropertyArray PropertyNames::LMDBProps { .name="LMDB", .prefixOnly=true, + .isOptIn=false, .properties=LMDBPropsData, - .length=2, - .isOptIn=false + .length=2 }; const Property IcePropsData[] = @@ -199,9 +199,9 @@ const PropertyArray PropertyNames::IceProps { .name="Ice", .prefixOnly=false, + .isOptIn=false, .properties=IcePropsData, - .length=83, - .isOptIn=false + .length=83 }; const Property IceMXPropsData[] = @@ -218,9 +218,9 @@ const PropertyArray PropertyNames::IceMXProps { .name="IceMX", .prefixOnly=false, + .isOptIn=false, .properties=IceMXPropsData, - .length=6, - .isOptIn=false + .length=6 }; const Property IceDiscoveryPropsData[] = @@ -242,9 +242,9 @@ const PropertyArray PropertyNames::IceDiscoveryProps { .name="IceDiscovery", .prefixOnly=false, + .isOptIn=false, .properties=IceDiscoveryPropsData, - .length=11, - .isOptIn=false + .length=11 }; const Property IceLocatorDiscoveryPropsData[] = @@ -266,9 +266,9 @@ const PropertyArray PropertyNames::IceLocatorDiscoveryProps { .name="IceLocatorDiscovery", .prefixOnly=false, + .isOptIn=false, .properties=IceLocatorDiscoveryPropsData, - .length=11, - .isOptIn=false + .length=11 }; const Property IceBoxPropsData[] = @@ -285,9 +285,9 @@ const PropertyArray PropertyNames::IceBoxProps { .name="IceBox", .prefixOnly=false, + .isOptIn=true, .properties=IceBoxPropsData, - .length=6, - .isOptIn=true + .length=6 }; const Property IceBoxAdminPropsData[] = @@ -299,9 +299,9 @@ const PropertyArray PropertyNames::IceBoxAdminProps { .name="IceBoxAdmin", .prefixOnly=false, + .isOptIn=true, .properties=IceBoxAdminPropsData, - .length=1, - .isOptIn=true + .length=1 }; const Property IceBridgePropsData[] = @@ -315,9 +315,9 @@ const PropertyArray PropertyNames::IceBridgeProps { .name="IceBridge", .prefixOnly=false, + .isOptIn=true, .properties=IceBridgePropsData, - .length=3, - .isOptIn=true + .length=3 }; const Property IceGridAdminPropsData[] = @@ -341,9 +341,9 @@ const PropertyArray PropertyNames::IceGridAdminProps { .name="IceGridAdmin", .prefixOnly=false, + .isOptIn=true, .properties=IceGridAdminPropsData, - .length=13, - .isOptIn=true + .length=13 }; const Property IceGridPropsData[] = @@ -416,9 +416,9 @@ const PropertyArray PropertyNames::IceGridProps { .name="IceGrid", .prefixOnly=false, + .isOptIn=true, .properties=IceGridPropsData, - .length=62, - .isOptIn=true + .length=62 }; const Property IceSSLPropsData[] = @@ -450,9 +450,9 @@ const PropertyArray PropertyNames::IceSSLProps { .name="IceSSL", .prefixOnly=false, + .isOptIn=false, .properties=IceSSLPropsData, - .length=21, - .isOptIn=false + .length=21 }; const Property IceStormPropsData[] = @@ -487,9 +487,9 @@ const PropertyArray PropertyNames::IceStormProps { .name="IceStorm", .prefixOnly=false, + .isOptIn=true, .properties=IceStormPropsData, - .length=24, - .isOptIn=true + .length=24 }; const Property IceStormAdminPropsData[] = @@ -503,9 +503,9 @@ const PropertyArray PropertyNames::IceStormAdminProps { .name="IceStormAdmin", .prefixOnly=false, + .isOptIn=true, .properties=IceStormAdminPropsData, - .length=3, - .isOptIn=true + .length=3 }; const Property IceBTPropsData[] = @@ -518,9 +518,9 @@ const PropertyArray PropertyNames::IceBTProps { .name="IceBT", .prefixOnly=false, + .isOptIn=false, .properties=IceBTPropsData, - .length=2, - .isOptIn=false + .length=2 }; const Property Glacier2PropsData[] = @@ -555,9 +555,9 @@ const PropertyArray PropertyNames::Glacier2Props { .name="Glacier2", .prefixOnly=false, + .isOptIn=true, .properties=Glacier2PropsData, - .length=24, - .isOptIn=true + .length=24 }; const Property DataStormPropsData[] = @@ -581,9 +581,9 @@ const PropertyArray PropertyNames::DataStormProps { .name="DataStorm", .prefixOnly=false, + .isOptIn=true, .properties=DataStormPropsData, - .length=13, - .isOptIn=true + .length=13 }; const std::array PropertyNames::validProps = diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index b679b18b841..bef9b29b7d5 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -29,9 +29,9 @@ namespace IceInternal { const char* name; const bool prefixOnly; + const bool isOptIn; const Property* properties; const int length; - const bool isOptIn; }; class PropertyNames diff --git a/cpp/test/IceBox/configuration/config.icebox2 b/cpp/test/IceBox/configuration/config.icebox2 index 56b137cf492..3c3df857eef 100644 --- a/cpp/test/IceBox/configuration/config.icebox2 +++ b/cpp/test/IceBox/configuration/config.icebox2 @@ -3,7 +3,6 @@ Ice.Admin.Endpoints=default -p 9996 -h 127.0.0.1 Ice.ProgramName=IceBox2 IceBox.InheritProperties=1 - TestInheritProperties=1 ServerProp=1 diff --git a/csharp/src/Ice/Internal/Property.cs b/csharp/src/Ice/Internal/Property.cs index 7c814b6c616..9e936d7a6f9 100644 --- a/csharp/src/Ice/Internal/Property.cs +++ b/csharp/src/Ice/Internal/Property.cs @@ -4,7 +4,7 @@ namespace Ice.Internal; -internal sealed record class PropertyArray(string name, bool prefixOnly, Property[] properties); +internal sealed record class PropertyArray(string name, bool prefixOnly, bool isOptIn, Property[] properties); internal sealed record class Property( string pattern, diff --git a/csharp/src/Ice/Internal/PropertyNames.cs b/csharp/src/Ice/Internal/PropertyNames.cs index 20687886313..ef29433c5ec 100644 --- a/csharp/src/Ice/Internal/PropertyNames.cs +++ b/csharp/src/Ice/Internal/PropertyNames.cs @@ -11,6 +11,7 @@ internal sealed class PropertyNames internal static PropertyArray ProxyProps = new( "Proxy", false, + false, [ new(pattern: @"EndpointSelection", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), new(pattern: @"ConnectionCached", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), @@ -26,6 +27,7 @@ internal sealed class PropertyNames internal static PropertyArray ConnectionProps = new( "Connection", true, + false, [ new(pattern: @"CloseTimeout", usesRegex: false, defaultValue: "10", deprecated: false, propertyArray: null), new(pattern: @"ConnectTimeout", usesRegex: false, defaultValue: "10", deprecated: false, propertyArray: null), @@ -38,6 +40,7 @@ internal sealed class PropertyNames internal static PropertyArray ThreadPoolProps = new( "ThreadPool", true, + false, [ new(pattern: @"Size", usesRegex: false, defaultValue: "1", deprecated: false, propertyArray: null), new(pattern: @"SizeMax", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), @@ -51,6 +54,7 @@ internal sealed class PropertyNames internal static PropertyArray ObjectAdapterProps = new( "ObjectAdapter", true, + false, [ new(pattern: @"AdapterId", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), new(pattern: @"Connection", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ConnectionProps), @@ -69,11 +73,13 @@ internal sealed class PropertyNames internal static PropertyArray LMDBProps = new( "LMDB", true, + false, []); internal static PropertyArray IceProps = new( "Ice", false, + false, [ new(pattern: @"AcceptClassCycles", usesRegex: false, defaultValue: "0", deprecated: false, propertyArray: null), new(pattern: @"Admin", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ObjectAdapterProps), @@ -158,6 +164,7 @@ internal sealed class PropertyNames internal static PropertyArray IceMXProps = new( "IceMX", false, + false, [ new(pattern: @"^Metrics\.[^\s]+\.GroupBy$", usesRegex: true, defaultValue: "", deprecated: false, propertyArray: null), new(pattern: @"^Metrics\.[^\s]+\.Map$", usesRegex: true, defaultValue: "", deprecated: false, propertyArray: null), @@ -170,6 +177,7 @@ internal sealed class PropertyNames internal static PropertyArray IceDiscoveryProps = new( "IceDiscovery", false, + false, [ new(pattern: @"Multicast", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ObjectAdapterProps), new(pattern: @"Reply", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ObjectAdapterProps), @@ -187,6 +195,7 @@ internal sealed class PropertyNames internal static PropertyArray IceLocatorDiscoveryProps = new( "IceLocatorDiscovery", false, + false, [ new(pattern: @"Reply", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ObjectAdapterProps), new(pattern: @"Locator", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: ObjectAdapterProps), @@ -204,6 +213,7 @@ internal sealed class PropertyNames internal static PropertyArray IceBoxProps = new( "IceBox", false, + true, [ new(pattern: @"InheritProperties", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), new(pattern: @"LoadOrder", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), @@ -216,26 +226,31 @@ internal sealed class PropertyNames internal static PropertyArray IceBoxAdminProps = new( "IceBoxAdmin", false, + true, []); internal static PropertyArray IceBridgeProps = new( "IceBridge", false, + true, []); internal static PropertyArray IceGridAdminProps = new( "IceGridAdmin", false, + true, []); internal static PropertyArray IceGridProps = new( "IceGrid", false, + true, []); internal static PropertyArray IceSSLProps = new( "IceSSL", false, + false, [ new(pattern: @"CAs", usesRegex: false, defaultValue: "", deprecated: false, propertyArray: null), new(pattern: @"CertStore", usesRegex: false, defaultValue: "My", deprecated: false, propertyArray: null), @@ -258,26 +273,31 @@ internal sealed class PropertyNames internal static PropertyArray IceStormProps = new( "IceStorm", false, + true, []); internal static PropertyArray IceStormAdminProps = new( "IceStormAdmin", false, + true, []); internal static PropertyArray IceBTProps = new( "IceBT", false, + false, []); internal static PropertyArray Glacier2Props = new( "Glacier2", false, + true, []); internal static PropertyArray DataStormProps = new( "DataStorm", false, + true, []); internal static PropertyArray[] validProps = diff --git a/csharp/src/Ice/ObjectAdapter.cs b/csharp/src/Ice/ObjectAdapter.cs index b52fe2d16ab..14e98081440 100644 --- a/csharp/src/Ice/ObjectAdapter.cs +++ b/csharp/src/Ice/ObjectAdapter.cs @@ -765,7 +765,6 @@ public void setLocator(LocatorPrx? locator) { lock (_mutex) { - checkForDeactivation(); return _locatorInfo?.getLocator(); } } diff --git a/csharp/src/Ice/Properties.cs b/csharp/src/Ice/Properties.cs index 365d0f919f9..f17df2b4119 100644 --- a/csharp/src/Ice/Properties.cs +++ b/csharp/src/Ice/Properties.cs @@ -37,6 +37,8 @@ public Properties() { } + public Properties(List optInPrefixes) => _optInPrefixes = optInPrefixes; + /// /// Initializes a new instance of the class. The property set is initialized from the /// provided argument vector. @@ -55,6 +57,8 @@ public Properties(ref string[] args, Properties? defaults = null) { _properties[entry.Key] = entry.Value.Clone(); } + + _optInPrefixes.AddRange(defaults._optInPrefixes); } if (_properties.TryGetValue("Ice.ProgramName", out PropertyValue? pv)) @@ -324,6 +328,12 @@ public void setProperty(string key, string value) // Check if the property is in an Ice property prefix. If so, check that it's a valid property. if (findIcePropertyArray(key) is PropertyArray propertyArray) { + if (propertyArray.isOptIn && !_optInPrefixes.Contains(propertyArray.name)) + { + throw new PropertyException( + $"Unable to set '{key}': property prefix '{propertyArray.name}' is opt-in and must be explicitly enabled"); + } + Property prop = findProperty(key[(propertyArray.name.Length + 1)..], propertyArray) ?? throw new PropertyException($"unknown Ice property: {key}"); // If the property is deprecated, log a warning. @@ -842,5 +852,6 @@ private void loadConfig() } private readonly Dictionary _properties = []; + private readonly List _optInPrefixes = []; private readonly object _mutex = new(); } diff --git a/csharp/src/IceBoxNet/Server.cs b/csharp/src/IceBoxNet/Server.cs index 6e5634efdbc..9cb67460575 100644 --- a/csharp/src/IceBoxNet/Server.cs +++ b/csharp/src/IceBoxNet/Server.cs @@ -55,7 +55,7 @@ public static int Main(string[] args) int status = 0; Ice.InitializationData initData = new Ice.InitializationData(); - initData.properties = new Ice.Properties(); + initData.properties = new Ice.Properties(["IceBox"]); initData.properties.setProperty("Ice.Admin.DelayCreation", "1"); try diff --git a/csharp/src/IceBoxNet/ServiceManagerI.cs b/csharp/src/IceBoxNet/ServiceManagerI.cs index 22576920e50..4cd3252fed5 100644 --- a/csharp/src/IceBoxNet/ServiceManagerI.cs +++ b/csharp/src/IceBoxNet/ServiceManagerI.cs @@ -896,21 +896,20 @@ public StartServiceInfo(string service, string value, string[] serverArgs) private Ice.Properties createServiceProperties(string service) { - Ice.Properties properties; + var properties = new Ice.Properties(); Ice.Properties communicatorProperties = _communicator.getProperties(); if (communicatorProperties.getIcePropertyAsInt("IceBox.InheritProperties") > 0) { - properties = communicatorProperties.Clone(); - // Inherit all except Ice.Admin.xxx properties - foreach (string p in properties.getPropertiesForPrefix("Ice.Admin.").Keys) + // Inherit all except IceBox. and Ice.Admin. properties + foreach (var property in communicatorProperties.getPropertiesForPrefix("")) { - properties.setProperty(p, ""); + if (!property.Key.StartsWith("IceBox.", StringComparison.Ordinal) && + !property.Key.StartsWith("Ice.Admin.", StringComparison.Ordinal)) + { + properties.setProperty(property.Key, property.Value); + } } } - else - { - properties = new Ice.Properties(); - } string programName = communicatorProperties.getIceProperty("Ice.ProgramName"); if (programName.Length == 0) diff --git a/csharp/test/Ice/properties/Client.cs b/csharp/test/Ice/properties/Client.cs index c699b211711..784e3e385dc 100644 --- a/csharp/test/Ice/properties/Client.cs +++ b/csharp/test/Ice/properties/Client.cs @@ -164,6 +164,18 @@ public override void run(string[] args) } Console.Out.WriteLine("ok"); + + Console.Out.Write("testing that setting a property in an opt-in prefix that is not configured throws an exception..."); + Console.Out.Flush(); + try + { + properties.setProperty("IceGrid.InstanceName", "TestGrid"); + test(false); + } + catch (Ice.PropertyException) + { + } + Console.Out.WriteLine("ok"); } } diff --git a/csharp/test/IceBox/configuration/AllTests.cs b/csharp/test/IceBox/configuration/AllTests.cs index 9e689be4a8c..d9867a15c0a 100644 --- a/csharp/test/IceBox/configuration/AllTests.cs +++ b/csharp/test/IceBox/configuration/AllTests.cs @@ -16,7 +16,7 @@ public static void allTests(Test.TestHelper helper) TestIntfPrx service4 = TestIntfPrxHelper.uncheckedCast(communicator.stringToProxy("test:" + helper.getTestEndpoint(3))); - if (service1.getProperty("IceBox.InheritProperties").Length == 0) + if (service1.getProperty("TestInheritProperties").Length == 0) { Console.Out.Write("testing service properties... "); Console.Out.Flush(); @@ -33,7 +33,6 @@ public static void allTests(Test.TestHelper helper) test(service2.getProperty("Ice.ProgramName") == "Test"); test(service2.getProperty("Service") == "2"); test(service2.getProperty("Service1.ArgProp").Length == 0); - test(service2.getProperty("IceBox.InheritProperties") == "1"); string[] args2 = { "--Service1.ArgProp=1" }; test(Enumerable.SequenceEqual(service2.getArgs(), args2)); diff --git a/csharp/test/IceBox/configuration/config.icebox b/csharp/test/IceBox/configuration/config.icebox index e290f851fca..22cb86f8636 100644 --- a/csharp/test/IceBox/configuration/config.icebox +++ b/csharp/test/IceBox/configuration/config.icebox @@ -3,7 +3,7 @@ Ice.Admin.Endpoints=default -p 9996 -h 127.0.0.1 Ice.ProgramName=IceBox IceBox.Service.Service1=msbuild/testservice/net8.0/testservice.dll:TestServiceI --Ice.Config=config.service1 --Service1.ArgProp=1 --Service1.Ovrd=2 --Service1.Unset= -a --Arg=2 -IceBox.Service.Service2=msbuild/testservice/net8.0/testservice.dll:TestServiceI --Ice.Config=config.service2 --Service1.ArgProp=1 --IceBox.InheritProperties +IceBox.Service.Service2=msbuild/testservice/net8.0/testservice.dll:TestServiceI --Ice.Config=config.service2 --Service1.ArgProp=1 IceBox.UseSharedCommunicator.Service3=1 IceBox.Service.Service3=msbuild/testservice/net8.0/testservice.dll:TestServiceI --Ice.Config=config.service3 diff --git a/csharp/test/IceBox/configuration/config.icebox2 b/csharp/test/IceBox/configuration/config.icebox2 index 965a34ec0ae..a72b94e8b5d 100644 --- a/csharp/test/IceBox/configuration/config.icebox2 +++ b/csharp/test/IceBox/configuration/config.icebox2 @@ -3,6 +3,7 @@ Ice.Admin.Endpoints=default -p 9996 -h 127.0.0.1 Ice.ProgramName=IceBox2 IceBox.InheritProperties=1 +TestInheritProperties=1 ServerProp=1 OverrideMe=1 diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java index 1f6f516ba01..2da766ff0dc 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java @@ -863,7 +863,6 @@ public synchronized void setLocator(LocatorPrx locator) { * @see #setLocator */ public synchronized LocatorPrx getLocator() { - checkForDeactivation(); if (_locatorInfo == null) { return null; } else { diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Properties.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Properties.java index b78d79b028c..837e8c29e13 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Properties.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Properties.java @@ -29,6 +29,10 @@ public PropertyValue clone() { /** Creates a new empty property set. */ public Properties() {} + public Properties(java.util.List optInPrefixes) { + _optInPrefixes.addAll(optInPrefixes); + } + /** * Creates a property set initialized from an argument vector. * @@ -94,6 +98,8 @@ public Properties(String[] args, Properties defaults, java.util.List rem for (java.util.Map.Entry p : defaults._properties.entrySet()) { _properties.put(p.getKey(), p.getValue().clone()); } + + _optInPrefixes.addAll(defaults._optInPrefixes); } boolean loadConfigFiles = false; @@ -361,6 +367,17 @@ public void setProperty(String key, String value) { // property. PropertyArray propertyArray = findIcePropertyArray(key); if (propertyArray != null) { + if (propertyArray.isOptIn() + && _optInPrefixes.stream().noneMatch(propertyArray.name()::equals)) { + + throw new PropertyException( + "unable to set '" + + key + + "': property prefix '" + + propertyArray.name() + + "' is opt-in and must be explicitly enabled"); + } + Property prop = findProperty(key.substring(propertyArray.name().length() + 1), propertyArray); if (prop == null) { @@ -904,5 +921,6 @@ private static String getDefaultProperty(String key) { private static final int ParseStateKey = 0; private static final int ParseStateValue = 1; - private java.util.HashMap _properties = new java.util.HashMap<>(); + private final java.util.HashMap _properties = new java.util.HashMap<>(); + private final java.util.List _optInPrefixes = new java.util.ArrayList<>(); } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyArray.java b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyArray.java index 1b33dd42c8b..2e485fc874d 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyArray.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyArray.java @@ -2,4 +2,4 @@ package com.zeroc.Ice; -record PropertyArray(String name, boolean prefixOnly, Property[] properties) {} +record PropertyArray(String name, boolean prefixOnly, boolean isOptIn, Property[] properties) {} diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java index c69380e0492..bd30a6dfe40 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/PropertyNames.java @@ -11,6 +11,7 @@ final class PropertyNames public static final PropertyArray ProxyProps = new PropertyArray( "Proxy", false, + false, new Property[] { new Property("EndpointSelection", false, "", false, null), new Property("ConnectionCached", false, "", false, null), @@ -26,6 +27,7 @@ final class PropertyNames public static final PropertyArray ConnectionProps = new PropertyArray( "Connection", true, + false, new Property[] { new Property("CloseTimeout", false, "10", false, null), new Property("ConnectTimeout", false, "10", false, null), @@ -38,6 +40,7 @@ final class PropertyNames public static final PropertyArray ThreadPoolProps = new PropertyArray( "ThreadPool", true, + false, new Property[] { new Property("Size", false, "1", false, null), new Property("SizeMax", false, "", false, null), @@ -51,6 +54,7 @@ final class PropertyNames public static final PropertyArray ObjectAdapterProps = new PropertyArray( "ObjectAdapter", true, + false, new Property[] { new Property("AdapterId", false, "", false, null), new Property("Connection", false, "", false, PropertyNames.ConnectionProps), @@ -69,12 +73,14 @@ final class PropertyNames public static final PropertyArray LMDBProps = new PropertyArray( "LMDB", true, + false, new Property[] { }); public static final PropertyArray IceProps = new PropertyArray( "Ice", false, + false, new Property[] { new Property("AcceptClassCycles", false, "0", false, null), new Property("Admin", false, "", false, PropertyNames.ObjectAdapterProps), @@ -163,6 +169,7 @@ final class PropertyNames public static final PropertyArray IceMXProps = new PropertyArray( "IceMX", false, + false, new Property[] { new Property("Metrics\\.[^\\s]+\\.GroupBy", true, "", false, null), new Property("Metrics\\.[^\\s]+\\.Map", true, "", false, null), @@ -175,6 +182,7 @@ final class PropertyNames public static final PropertyArray IceDiscoveryProps = new PropertyArray( "IceDiscovery", false, + false, new Property[] { new Property("Multicast", false, "", false, PropertyNames.ObjectAdapterProps), new Property("Reply", false, "", false, PropertyNames.ObjectAdapterProps), @@ -192,6 +200,7 @@ final class PropertyNames public static final PropertyArray IceLocatorDiscoveryProps = new PropertyArray( "IceLocatorDiscovery", false, + false, new Property[] { new Property("Reply", false, "", false, PropertyNames.ObjectAdapterProps), new Property("Locator", false, "", false, PropertyNames.ObjectAdapterProps), @@ -209,6 +218,7 @@ final class PropertyNames public static final PropertyArray IceBoxProps = new PropertyArray( "IceBox", false, + true, new Property[] { new Property("InheritProperties", false, "", false, null), new Property("LoadOrder", false, "", false, null), @@ -221,6 +231,7 @@ final class PropertyNames public static final PropertyArray IceBoxAdminProps = new PropertyArray( "IceBoxAdmin", false, + true, new Property[] { new Property("ServiceManager.Proxy", false, "", false, PropertyNames.ProxyProps) }); @@ -228,12 +239,14 @@ final class PropertyNames public static final PropertyArray IceBridgeProps = new PropertyArray( "IceBridge", false, + true, new Property[] { }); public static final PropertyArray IceGridAdminProps = new PropertyArray( "IceGridAdmin", false, + true, new Property[] { new Property("MetricsConfig", false, "", false, null), new Property("Trace.Observers", false, "", false, null), @@ -243,12 +256,14 @@ final class PropertyNames public static final PropertyArray IceGridProps = new PropertyArray( "IceGrid", false, + true, new Property[] { }); public static final PropertyArray IceSSLProps = new PropertyArray( "IceSSL", false, + false, new Property[] { new Property("Alias", false, "", false, null), new Property("CheckCertName", false, "0", false, null), @@ -272,18 +287,21 @@ final class PropertyNames public static final PropertyArray IceStormProps = new PropertyArray( "IceStorm", false, + true, new Property[] { }); public static final PropertyArray IceStormAdminProps = new PropertyArray( "IceStormAdmin", false, + true, new Property[] { }); public static final PropertyArray IceBTProps = new PropertyArray( "IceBT", false, + false, new Property[] { new Property("RcvSize", false, "", false, null), new Property("SndSize", false, "", false, null) @@ -292,12 +310,14 @@ final class PropertyNames public static final PropertyArray Glacier2Props = new PropertyArray( "Glacier2", false, + true, new Property[] { }); public static final PropertyArray DataStormProps = new PropertyArray( "DataStorm", false, + true, new Property[] { }); diff --git a/java/src/IceBox/src/main/java/com/zeroc/IceBox/Admin.java b/java/src/IceBox/src/main/java/com/zeroc/IceBox/Admin.java index 33c335e7f98..fa0444aa794 100644 --- a/java/src/IceBox/src/main/java/com/zeroc/IceBox/Admin.java +++ b/java/src/IceBox/src/main/java/com/zeroc/IceBox/Admin.java @@ -2,6 +2,8 @@ package com.zeroc.IceBox; +import java.util.Collections; + public final class Admin { private static void usage() { System.err.println( @@ -18,10 +20,14 @@ private static void usage() { public static void main(String[] args) { int status = 0; - java.util.List commands = new java.util.ArrayList(); + java.util.List commands = new java.util.ArrayList<>(); + + com.zeroc.Ice.InitializationData initData = new com.zeroc.Ice.InitializationData(); + initData.properties = + new com.zeroc.Ice.Properties(Collections.singletonList("IceBoxAdmin")); try (com.zeroc.Ice.Communicator communicator = - com.zeroc.Ice.Util.initialize(args, commands)) { + com.zeroc.Ice.Util.initialize(args, initData, commands)) { Runtime.getRuntime() .addShutdownHook( new Thread( diff --git a/java/src/IceBox/src/main/java/com/zeroc/IceBox/Server.java b/java/src/IceBox/src/main/java/com/zeroc/IceBox/Server.java index e9242066bf5..74a2ad99b91 100644 --- a/java/src/IceBox/src/main/java/com/zeroc/IceBox/Server.java +++ b/java/src/IceBox/src/main/java/com/zeroc/IceBox/Server.java @@ -2,6 +2,8 @@ package com.zeroc.IceBox; +import java.util.Collections; + public final class Server { static class ShutdownHook extends Thread { private com.zeroc.Ice.Communicator _communicator; @@ -80,10 +82,10 @@ private static int run(com.zeroc.Ice.Communicator communicator, java.util.List argSeq = new java.util.ArrayList(); + java.util.List argSeq = new java.util.ArrayList<>(); com.zeroc.Ice.InitializationData initData = new com.zeroc.Ice.InitializationData(); - initData.properties = new com.zeroc.Ice.Properties(); + initData.properties = new com.zeroc.Ice.Properties(Collections.singletonList("IceBox")); initData.properties.setProperty("Ice.Admin.DelayCreation", "1"); ShutdownHook shutdownHook = null; diff --git a/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java b/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java index 89c73a69c11..5c1d16795e8 100644 --- a/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java +++ b/java/src/IceBox/src/main/java/com/zeroc/IceBox/ServiceManagerI.java @@ -799,16 +799,18 @@ static class StartServiceInfo { } private Properties createServiceProperties(String service) { - Properties properties; + Properties properties = new Properties(); Properties communicatorProperties = _communicator.getProperties(); if (communicatorProperties.getPropertyAsInt("IceBox.InheritProperties") > 0) { - properties = communicatorProperties._clone(); - // Inherit all except Ice.Admin.xxx properties - for (String p : properties.getPropertiesForPrefix("Ice.Admin.").keySet()) { - properties.setProperty(p, ""); + + // Inherit all except IceBox. and Ice.Admin. properties + for (java.util.Map.Entry p : + communicatorProperties.getPropertiesForPrefix("").entrySet()) { + String key = p.getKey(); + if (!key.startsWith("IceBox.") && !key.startsWith("Ice.Admin.")) { + properties.setProperty(key, p.getValue()); + } } - } else { - properties = new Properties(); } String programName = communicatorProperties.getProperty("Ice.ProgramName"); diff --git a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java index be18fb4dc9c..b35ab6be9d0 100644 --- a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java +++ b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java @@ -29,6 +29,7 @@ import java.security.KeyStore.TrustedCertificateEntry; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.Collections; import java.util.Enumeration; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -2255,7 +2256,8 @@ public JFileChooser getSaveIceLogChooser() { private static com.zeroc.Ice.Properties createProperties( String[] args, java.util.List rArgs) { - com.zeroc.Ice.Properties properties = new com.zeroc.Ice.Properties(); + com.zeroc.Ice.Properties properties = + new com.zeroc.Ice.Properties(Collections.singletonList("IceGridAdmin")); // Disable retries properties.setProperty("Ice.RetryIntervals", "-1"); diff --git a/java/test/src/main/java/test/Ice/properties/Client.java b/java/test/src/main/java/test/Ice/properties/Client.java index 9f45ce4a9f7..4b1534825a8 100644 --- a/java/test/src/main/java/test/Ice/properties/Client.java +++ b/java/test/src/main/java/test/Ice/properties/Client.java @@ -15,6 +15,7 @@ public static void test(boolean b) { } } + @Override public void run(String[] args) { { System.out.print("testing load properties from UTF-8 path... "); @@ -160,9 +161,20 @@ public void run(String[] args) { } catch (PropertyException ex) { } System.out.println("ok"); + + System.out.print( + "testing that setting a property in an opt-in prefix that is not configured" + + " throws an exception..."); + System.out.flush(); + try { + properties.setProperty("IceGrid.InstanceName", "TestGrid"); + test(false); + } catch (PropertyException ex) { + } + System.out.println("ok"); } } } - private static String configPath = "./config/\u4E2D\u56FD_client.config"; + private static final String configPath = "./config/\u4E2D\u56FD_client.config"; } diff --git a/java/test/src/main/java/test/IceBox/configuration/AllTests.java b/java/test/src/main/java/test/IceBox/configuration/AllTests.java index 3150d8e64ca..e5ebffc8a32 100644 --- a/java/test/src/main/java/test/IceBox/configuration/AllTests.java +++ b/java/test/src/main/java/test/IceBox/configuration/AllTests.java @@ -21,7 +21,7 @@ public static void allTests(test.TestHelper helper) { var service3 = TestIntfPrx.createProxy(communicator, "test:" + helper.getTestEndpoint(2)); var service4 = TestIntfPrx.createProxy(communicator, "test:" + helper.getTestEndpoint(3)); - if (service1.getProperty("IceBox.InheritProperties").isEmpty()) { + if (service1.getProperty("TestInheritProperties").isEmpty()) { out.print("testing service properties... "); out.flush(); @@ -37,7 +37,6 @@ public static void allTests(test.TestHelper helper) { test(service2.getProperty("Ice.ProgramName").equals("Test")); test(service2.getProperty("Service").equals("2")); test(service2.getProperty("Service1.ArgProp").isEmpty()); - test(service2.getProperty("IceBox.InheritProperties").equals("1")); String[] args2 = {"--Service1.ArgProp=1"}; test(java.util.Arrays.equals(service2.getArgs(), args2)); diff --git a/java/test/src/main/java/test/IceBox/configuration/config.icebox b/java/test/src/main/java/test/IceBox/configuration/config.icebox index 1dd4b90957c..c4ece8fb977 100644 --- a/java/test/src/main/java/test/IceBox/configuration/config.icebox +++ b/java/test/src/main/java/test/IceBox/configuration/config.icebox @@ -3,7 +3,7 @@ Ice.Admin.Endpoints=default -p 9996 -h 127.0.0.1 Ice.ProgramName=IceBox IceBox.Service.Service1=test.IceBox.configuration.TestServiceI --Ice.Config=config.service1 --Service1.ArgProp=1 --Service1.Ovrd=2 --Service1.Unset= -a --Arg=2 -IceBox.Service.Service2=test.IceBox.configuration.TestServiceI --Ice.Config=config.service2 --Service1.ArgProp=1 --IceBox.InheritProperties +IceBox.Service.Service2=test.IceBox.configuration.TestServiceI --Ice.Config=config.service2 --Service1.ArgProp=1 IceBox.UseSharedCommunicator.Service3=1 IceBox.Service.Service3=test.IceBox.configuration.TestServiceI --Ice.Config=config.service3 diff --git a/java/test/src/main/java/test/IceBox/configuration/config.icebox2 b/java/test/src/main/java/test/IceBox/configuration/config.icebox2 index 2866764f19f..4ee84ed963f 100644 --- a/java/test/src/main/java/test/IceBox/configuration/config.icebox2 +++ b/java/test/src/main/java/test/IceBox/configuration/config.icebox2 @@ -3,6 +3,7 @@ Ice.Admin.Endpoints=default -p 9996 -h 127.0.0.1 Ice.ProgramName=IceBox2 IceBox.InheritProperties=1 +TestInheritProperties=1 ServerProp=1 OverrideMe=1 diff --git a/js/src/Ice/Property.js b/js/src/Ice/Property.js index ea056e5099d..0e1bda2843d 100644 --- a/js/src/Ice/Property.js +++ b/js/src/Ice/Property.js @@ -11,9 +11,10 @@ export class Property { } export class PropertyArray { - constructor(name, prefixOnly, properties) { + constructor(name, prefixOnly, isOptIn, properties) { this.name = name; this.prefixOnly = prefixOnly; + this.isOptIn = isOptIn; this.properties = properties; } } diff --git a/js/src/Ice/PropertyNames.js b/js/src/Ice/PropertyNames.js index eaa1bca3e8c..e1bee7d57a5 100644 --- a/js/src/Ice/PropertyNames.js +++ b/js/src/Ice/PropertyNames.js @@ -8,7 +8,7 @@ import { Property, PropertyArray } from "./Property.js"; export const PropertyNames = {}; -PropertyNames.ProxyProps = new PropertyArray("Proxy", false); +PropertyNames.ProxyProps = new PropertyArray("Proxy", false, false); PropertyNames.ProxyProps.properties = [ new Property("EndpointSelection", false, "", false, null), new Property("ConnectionCached", false, "", false, null), @@ -20,7 +20,7 @@ PropertyNames.ProxyProps.properties = [ new Property(/^Context\../, true, "", false, null) ]; -PropertyNames.ConnectionProps = new PropertyArray("Connection", true); +PropertyNames.ConnectionProps = new PropertyArray("Connection", true, false); PropertyNames.ConnectionProps.properties = [ new Property("CloseTimeout", false, "10", false, null), new Property("ConnectTimeout", false, "10", false, null), @@ -29,11 +29,11 @@ PropertyNames.ConnectionProps.properties = [ new Property("InactivityTimeout", false, "300", false, null) ]; -PropertyNames.ThreadPoolProps = new PropertyArray("ThreadPool", true); +PropertyNames.ThreadPoolProps = new PropertyArray("ThreadPool", true, false); PropertyNames.ThreadPoolProps.properties = [ ]; -PropertyNames.ObjectAdapterProps = new PropertyArray("ObjectAdapter", true); +PropertyNames.ObjectAdapterProps = new PropertyArray("ObjectAdapter", true, false); PropertyNames.ObjectAdapterProps.properties = [ new Property("PublishedEndpoints", false, "", false, null), new Property("Router", false, "", false, PropertyNames.ProxyProps), @@ -41,11 +41,11 @@ PropertyNames.ObjectAdapterProps.properties = [ new Property("MessageSizeMax", false, "", false, null) ]; -PropertyNames.LMDBProps = new PropertyArray("LMDB", true); +PropertyNames.LMDBProps = new PropertyArray("LMDB", true, false); PropertyNames.LMDBProps.properties = [ ]; -PropertyNames.IceProps = new PropertyArray("Ice", false); +PropertyNames.IceProps = new PropertyArray("Ice", false, false); PropertyNames.IceProps.properties = [ new Property("BackgroundLocatorCacheUpdates", false, "0", false, null), new Property("BatchAutoFlush", false, "", true, null), @@ -79,59 +79,59 @@ PropertyNames.IceProps.properties = [ new Property("Warn.UnusedProperties", false, "0", false, null) ]; -PropertyNames.IceMXProps = new PropertyArray("IceMX", false); +PropertyNames.IceMXProps = new PropertyArray("IceMX", false, false); PropertyNames.IceMXProps.properties = [ ]; -PropertyNames.IceDiscoveryProps = new PropertyArray("IceDiscovery", false); +PropertyNames.IceDiscoveryProps = new PropertyArray("IceDiscovery", false, false); PropertyNames.IceDiscoveryProps.properties = [ ]; -PropertyNames.IceLocatorDiscoveryProps = new PropertyArray("IceLocatorDiscovery", false); +PropertyNames.IceLocatorDiscoveryProps = new PropertyArray("IceLocatorDiscovery", false, false); PropertyNames.IceLocatorDiscoveryProps.properties = [ ]; -PropertyNames.IceBoxProps = new PropertyArray("IceBox", false); +PropertyNames.IceBoxProps = new PropertyArray("IceBox", false, true); PropertyNames.IceBoxProps.properties = [ ]; -PropertyNames.IceBoxAdminProps = new PropertyArray("IceBoxAdmin", false); +PropertyNames.IceBoxAdminProps = new PropertyArray("IceBoxAdmin", false, true); PropertyNames.IceBoxAdminProps.properties = [ ]; -PropertyNames.IceBridgeProps = new PropertyArray("IceBridge", false); +PropertyNames.IceBridgeProps = new PropertyArray("IceBridge", false, true); PropertyNames.IceBridgeProps.properties = [ ]; -PropertyNames.IceGridAdminProps = new PropertyArray("IceGridAdmin", false); +PropertyNames.IceGridAdminProps = new PropertyArray("IceGridAdmin", false, true); PropertyNames.IceGridAdminProps.properties = [ ]; -PropertyNames.IceGridProps = new PropertyArray("IceGrid", false); +PropertyNames.IceGridProps = new PropertyArray("IceGrid", false, true); PropertyNames.IceGridProps.properties = [ ]; -PropertyNames.IceSSLProps = new PropertyArray("IceSSL", false); +PropertyNames.IceSSLProps = new PropertyArray("IceSSL", false, false); PropertyNames.IceSSLProps.properties = [ ]; -PropertyNames.IceStormProps = new PropertyArray("IceStorm", false); +PropertyNames.IceStormProps = new PropertyArray("IceStorm", false, true); PropertyNames.IceStormProps.properties = [ ]; -PropertyNames.IceStormAdminProps = new PropertyArray("IceStormAdmin", false); +PropertyNames.IceStormAdminProps = new PropertyArray("IceStormAdmin", false, true); PropertyNames.IceStormAdminProps.properties = [ ]; -PropertyNames.IceBTProps = new PropertyArray("IceBT", false); +PropertyNames.IceBTProps = new PropertyArray("IceBT", false, false); PropertyNames.IceBTProps.properties = [ ]; -PropertyNames.Glacier2Props = new PropertyArray("Glacier2", false); +PropertyNames.Glacier2Props = new PropertyArray("Glacier2", false, true); PropertyNames.Glacier2Props.properties = [ ]; -PropertyNames.DataStormProps = new PropertyArray("DataStorm", false); +PropertyNames.DataStormProps = new PropertyArray("DataStorm", false, true); PropertyNames.DataStormProps.properties = [ ]; diff --git a/python/modules/IcePy/ObjectAdapter.cpp b/python/modules/IcePy/ObjectAdapter.cpp index a0c90ee3d62..87e8e980a65 100644 --- a/python/modules/IcePy/ObjectAdapter.cpp +++ b/python/modules/IcePy/ObjectAdapter.cpp @@ -1393,16 +1393,7 @@ extern "C" PyObject* adapterGetLocator(ObjectAdapterObject* self, PyObject* /*args*/) { assert(self->adapter); - optional locator; - try - { - locator = (*self->adapter)->getLocator(); - } - catch (...) - { - setPythonException(current_exception()); - return nullptr; - } + optional locator = (*self->adapter)->getLocator(); if (!locator) {