bugGNU Octave - Bugs: bug #62011, accessing protected property in...


bug #62011: accessing protected property in classdef function raises access error after creating function handle

Submitter:  None
Submitted:  Tue 08 Feb 2022 01:43:06 PM UTC
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


( Jump to the original submission )

Wed 09 Feb 2022 12:06:22 PM UTC, comment #7: 

I can reproduce the error with the updated sequence of commands from comment #6 with Octave 6.4.0 on Windows.
Still the same for Octave 7.0.90.

Markus Mützel <mmuetzel>
Project Member
Wed 09 Feb 2022 11:41:47 AM UTC, comment #6: 

Another refinement for reproduction: As for me

'clear all; @inputParser; parsertest("mech")'

is NOT giving any error, but

'clear all; parsertest("mech"); @inputParser; parsertest("mech")'

DOES (so it seems one needs to call the function twice…)

Eldrad Ulthran <eldrad_ulthran>
Wed 09 Feb 2022 11:32:21 AM UTC, comment #5: 

GNU Octave installed from Opensuse Tumbleweed Repository.

which inputParser.m
'inputParser.m' is the file /usr/share/octave/6.4.0/m/miscellaneous/inputParser.m

Eldrad Ulthran <eldrad_ulthran>
Wed 09 Feb 2022 11:28:30 AM UTC, comment #4: 

Still cannot reproduce with the updated steps with Octave 6.4.0 on Windows. Maybe a Linux-only bug?

Where did you get Octave from? Did you build it yourself?

Again: What does `which inputParser.m` return for you?

Markus Mützel <mmuetzel>
Project Member
Wed 09 Feb 2022 10:48:26 AM UTC, comment #3: 

GNU/Linux is correct. (sorry, forgot to login before posting)

I was able to narrow down the strange behaviour to a very obscure edge case. When the function is called in a cleared ("clear all") environment, it works without a problem.
However, by accident I had typed "@inputParser" in the command window (I know, not a useful command), and after that calling the function created the strange error.
In order to reproduce it should be sufficient to reduce the function to the bare minimum:

function parsertest(varargin)
p = inputParser();
p.addRequired("pack", @ischar);

'clear all; parsertest("mech")'
works without problems, but
'@inputParser; parsertest("mech")'
not. Any subsequent useless command like '@bla' does not prevent the error from happening, only a 'clear all' does.

Eldrad Ulthran <eldrad_ulthran>
Tue 08 Feb 2022 09:59:29 PM UTC, comment #2: 

The Operating System for this bug is marked as "GNU/Linux"  Should it be "Microsoft Windows"?

Rik <rik5>
Project Administrator
Tue 08 Feb 2022 05:21:16 PM UTC, comment #1: 

Works for me with Octave 6.4.0 on Windows.

What does `which inputParser.m` return for you?

Attaching the function file for convenience.

(file #52824)

Markus Mützel <mmuetzel>
Project Member
Tue 08 Feb 2022 01:43:06 PM UTC, original submission:  

The example for the usage of inputParser from the manual is not executable and gives some strange error. The function code is copypasted (only renamed):

function parsertest (varargin)
  p = inputParser ();                      # create object
  p.FunctionName = "parsertest";                # set function name
  p.addRequired ("pack", @ischar);         # mandatory argument
  p.addOptional ("path", pwd(), @ischar);  # optional argument

  ## create a function handle to anonymous functions for validators
  val_mat = @(x) isvector (x) && all (x <= 1) && all (x >= 0);
  p.addOptional ("mat", [0 0], val_mat);

  ## create two arguments of type "Parameter"
  val_type = @(x) any (strcmp (x, {"linear", "quadratic"}));
  p.addParameter ("type", "linear", val_type);
  val_verb = @(x) any (strcmp (x, {"low", "medium", "high"}));
  p.addParameter ("tolerance", "low", val_verb);

  ## create a switch type of argument
  p.addSwitch ("verbose");

  p.parse (varargin{:});  # Run created parser on inputs

  ## the rest of the function can access inputs by using p.Results.
  ## for example, get the tolerance input with p.Results.tolerance

Now calling the function as described in the manual gives an error:

error: subsref: property 'Optional' has protected access and cannot be obtained in this context
error: called from
    addRequired at line 230 column 7
    parsertest at line 4 column 3

I'm not sure whether this is a bug inside addRequired or a wrong description in the manual…



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #52824:  parsertest.m added by mmuetzel (1021B - text/plain)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by eldrad_ulthran (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.





    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-03-04 mmuetzel CategoryOctave Function Classdef
    2022-02-09 mmuetzel Item GroupNone Unexpected Error or Warning
        StatusNeed Info Confirmed
        Release6.4.0 dev
        Operating SystemGNU/Linux Any
        SummaryaddRequired of inputParser raising "protected access" error accessing protected property in classdef function raises access error after creating function handle
    2022-02-08 mmuetzel Attached File- Added parsertest.m, #52824
        CategoryNone Octave Function
        StatusNone Need Info

    Back to the top

    Powered by Savane 3.9